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

How should I link to other Docker containers? #3

Open
johnjelinek opened this issue May 12, 2014 · 7 comments
Open

How should I link to other Docker containers? #3

johnjelinek opened this issue May 12, 2014 · 7 comments

Comments

@johnjelinek
Copy link
Contributor

I can link to other containers, but I cannot reference the environment variables in my sites-enabled/ conf files. Do you know of a good way to reference your linked containers?

@johnjelinek
Copy link
Contributor Author

I think a commit like this could help: phusion/passenger-docker@8aff974. It provides access to main.d/ where you can put env variables.

@johnjelinek
Copy link
Contributor Author

Off-topic: Am I correct in assuming that the only way to restart nginx to read new conf files is by recreating the container?

$ docker rm -f nginx; docker run --name nginx -d -p 80:80 -p 8080:8080 -v /home/admin/sites-enabled:/etc/nginx/sites-enabled -v /home/admin/nginx-logs:/var/log/nginx dockerfile/nginx

@DaleWebb
Copy link

Have you tried attaching to the container and running the nginx reload command?

@johnjelinek
Copy link
Contributor Author

Yes, the issue is that nginx needs Perl support to read environment
variables of linked containers. See here:
docker-library/nginx#1.
On Jul 14, 2014 5:10 AM, "Dale Webb" [email protected] wrote:

Have you tried attaching to the container and running the nginx reload
command?


Reply to this email directly or view it on GitHub
#3 (comment).

@eugene-dounar
Copy link

You can access linked containers by hostname. See the paragraph about generated /etc/hosts in https://docs.docker.com/userguide/dockerlinks/

@dimroc
Copy link
Contributor

dimroc commented Aug 13, 2014

Eugene's approach is indeed better. Here's an example based on eugene's link (https://docs.docker.com/userguide/dockerlinks/) with Vagrant:

config.vm.provision "docker", images: ["dockerfile/nginx", "dockerfile/elasticsearch"] do |d|
    # docker run -d -p 127.0.0.1:9200:9200 -p 127.0.0.1:9300:9300 dockerfile/elasticsearch # only allows localhost connections w 127.0.0.1
    d.run "dockerfile/elasticsearch", daemonize: true, args: "--name es -p 127.0.0.1:9200:9200 -p 127.0.0.1:9300:9300"

    # docker run -d -p 80:80 dockerfile/nginx
    d.run "dockerfile/nginx", daemonize: true, args: "--name nginx --link es:es -p 80:80 -p 443:443 -v /etc/nginx/sites-enabled:/etc/nginx/sites-enabled -v /var/log/nginx:/var/log/nginx"
  end

The configuration in sites-enabled:

server {
  listen                80 default_server;

  access_log            /var/log/nginx/elasticsearch.access.log;
  error_log            /var/log/nginx/elasticsearch.error.log;

  location / {
    proxy_pass http://es:9200;
    proxy_read_timeout 90;
  }
}

Linked docker parent containers automatically get the child's ip populated in the /etc/hosts file. Notice the http://es:9200, this is because es is in the /etc/hosts file.

@karabijavad
Copy link

pretty sure its at /etc/nginx/conf.d/ that the configuration needs to go

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

No branches or pull requests

5 participants