简体   繁体   中英

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!

如果不想每次都要重新启动代理容器之一时就重新启动代理容器(例如, ),则可以看看自动更新的代理配置方法: http : //jasonwilder.com/blog/2014/ 3月25日/自动化-nginx的-反向代理换搬运工/

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

if u use some modern version of docker the links in nginx container to your web service probably get updated (u can check it with docker exec -ti nginx bash - then cat /etc/hosts) - problem is nginx doesnt' use /etc/hosts every time - it caches the ip and when it changes - he gets lost. 'docker kill -s HUP nginx' which makes nginx reload its config without restart helps too.

I have the same problem. I used to start my services with systemd unit files - and when u make one service (nginx) dependant on other (webapp) and then restart the webapp - systemd is smart enough to restart the nginx as well. Now I'm trying my luck with docker-compose and restarting webapp container confuses nginx.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM