Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restarting Containers When Using Docker and Nginx proxy_pass

I have an nginx docker container and a webapp container successfully running and talking to eachother.

The nginx container listens on port 80, and uses proxy_pass to direct traffic to the IP of the webapp container.

upstream app_humansio { server humansio:8080 max_fails=3 fail_timeout=30s; }

"humansio" is set in the /etc/hosts file by docker because I've started nginx with --link humansio:humansio. The webapp container (humansio) is always exposing 8080.

The problem is, when I reload the webapp container, the link to the nginx container breaks and I need to restart that as well. Is there any way I can do this differently so I don't need to restart the nginx container when the webapp container reloads?

--

I've tried to do something like connecting them manually by using a common port (8001 on both), but since they actually reserve that port, the 2nd container cannot use it as well.

Thanks!

like image 276
Shane Reustle Avatar asked Sep 28 '22 15:09

Shane Reustle


2 Answers

I prefer to run the proxy (nginx of haproxy) directly on the host for this reason.

But an option is to "Link via an Ambassador Container" https://docs.docker.com/articles/ambassador_pattern_linking/

https://www.digitalocean.com/community/tutorials/how-to-use-the-ambassador-pattern-to-dynamically-configure-services-on-coreos

like image 59
Dave Albert Avatar answered Oct 05 '22 07:10

Dave Albert


If you don't want to restart your proxy container whenever you have to restart one of the proxied ones (e.g. fig), you could take a look at the autoupdated proxy configuration approach: http://jasonwilder.com/blog/2014/03/25/automated-nginx-reverse-proxy-for-docker/

like image 42
Mykola Gurov Avatar answered Oct 05 '22 07:10

Mykola Gurov