Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: Use some defaults when linking containers #6

Open
bompi88 opened this issue Feb 17, 2016 · 7 comments
Open

Suggestion: Use some defaults when linking containers #6

bompi88 opened this issue Feb 17, 2016 · 7 comments

Comments

@bompi88
Copy link
Contributor

bompi88 commented Feb 17, 2016

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
@Alino
Copy link
Owner

Alino commented Feb 17, 2016

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

@bompi88
Copy link
Contributor Author

bompi88 commented Feb 17, 2016

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?

@Alino
Copy link
Owner

Alino commented Feb 17, 2016

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

@bompi88
Copy link
Contributor Author

bompi88 commented Feb 17, 2016

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
Copy link
Contributor Author

bompi88 commented Feb 18, 2016

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

@Alino
Copy link
Owner

Alino commented Mar 31, 2016

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

@bompi88
Copy link
Contributor Author

bompi88 commented Mar 31, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants