Mongo2ES
Mongo2ES copied to clipboard
Suggestion: Use some defaults when linking containers
For the simplicity, when linking containers, use env variables like below if no other env variable is set.
MONGO_PORT_27017_TCP_ADDRandMONGO_PORT_27017_TCP_PORTELASTICSEARCH_PORT_9200_TCP_ADDRandELASTICSEARCH_PORT_9200_TCP_PORT
could you please describe with some example, how would you use those variables when linking docker containers? It's not clear to me yet :)
I'm kind of new to the whole docker thingy, but I think those variables are set if you link the elasticsearch and mongodb container with the --link option. A typical setup could be as follows, where the containers are linked to the mongo2es container at the bottom.
# Run data-only container
docker run \
--volume=/data/db/ \
--volume=/usr/share/elasticsearch/data \
--name=data-only \
--entrypoint=/bin/echo \
ubuntu 'Data-only container'
# Run mongodb container
docker run \
--publish=27017:27017 \
--volumes-from data-only \
--volume="$PWD/.mongodb.conf":/mongodb.conf \
--name=mongodb \
-d \
mongo mongod -f /mongodb.conf
# Run Elasticsearch
docker run \
--publish=9200:9200 \
--publish=9300:9300 \
--volumes-from data-only \
--name=elasticsearch \
-d \
elasticsearch
# Build mongoose container within .mongo2es dir
# docker build -t mongo2es .mongo2es
echo "Waiting for Elasticsearch to start"
docker-machine inspect --format '{{ .Driver.IPAddress }}:9200' dev | xargs wget --retry-connrefused --tries=5 -q --waitretry=3 --spider
sleep 1
# Run mongo2es container
docker run \
-e ROOT_URL=http://localhost:3001 \ # This could have a default value as well?
--link=mongodb \
--link=elasticsearch \
-p 3001:80 \
--name mongo2es \
-d \
mongo2es
In the mongo2es container, those variables are accessible, I think. If those are available you could set the MONGO_URL and so on, based on those? Just a suggestion, and I don't know if this option would be helpful or just misleading? What do you think about the matter?
so if I understand, docker automatically creates those env variables for you if you --link the containers. That's cool, I didn't know that.
You are right, we should make such a 'convention over configuration' that if you link the containers, all required env variables in mongo2es should get set based on those docker auto-generated env variables if they are not explicitly set to something else.
I will look into this issue later someday (I will be probably linking containers when I get my project which is using mongo2es into production).
Pull requests are welcome btw :)
Awesome :) maybe I'll investigate further next week, which kind of other variables being set and so on. My hands are quite tightened this week while working on my master thesis.
@Alino I looked into this anyway. Created a two PR's for you to take a look at :)
Good job, I just merged your PRs, but I am not sure about this one, I haven't tested it yet. Did you try it, or are you using this approach? is everything ok with it? Maybe I should keep it opened, and test it later
Haven't got the time to test it thoroughly yet, sorry.