Mongo2ES icon indicating copy to clipboard operation
Mongo2ES copied to clipboard

Suggestion: Use some defaults when linking containers

Open bompi88 opened this issue 9 years ago • 7 comments

For the simplicity, when linking containers, use env variables like below if no other env variable is set.

  • MONGO_PORT_27017_TCP_ADDR and MONGO_PORT_27017_TCP_PORT
  • ELASTICSEARCH_PORT_9200_TCP_ADDR and ELASTICSEARCH_PORT_9200_TCP_PORT

bompi88 avatar Feb 17 '16 09:02 bompi88

could you please describe with some example, how would you use those variables when linking docker containers? It's not clear to me yet :)

Alino avatar Feb 17 '16 14:02 Alino

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?

bompi88 avatar Feb 17 '16 17:02 bompi88

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 :)

Alino avatar Feb 17 '16 18:02 Alino

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.

bompi88 avatar Feb 17 '16 18:02 bompi88

@Alino I looked into this anyway. Created a two PR's for you to take a look at :)

bompi88 avatar Feb 18 '16 14:02 bompi88

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

Alino avatar Mar 31 '16 17:03 Alino

Haven't got the time to test it thoroughly yet, sorry.

bompi88 avatar Mar 31 '16 17:03 bompi88