使用 Docker 和 Nginx proxy_pass 时重启容器

Sha*_*tle 5 nginx proxypass docker

我有一个 nginx docker 容器和一个 webapp 容器成功运行并相互交谈。

nginx 容器侦听 80 端口,并使用 proxy_pass 将流量定向到 webapp 容器的 IP。

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

“humansio”是/etc/hosts由docker 在文件中设置的,因为我已经用--link humansio:humansio. webapp 容器 (humansio) 总是暴露 8080。

问题是,当我重新加载 webapp 容器时,到 nginx 容器的链接断开了,我也需要重新启动它。有什么办法可以以不同的方式执行此操作,以便在重新加载 webapp 容器时不需要重新启动 nginx 容器?

——

我曾尝试通过使用公共端口(两个端口均为 8001)手动连接它们,但由于它们实际上保留了该端口,因此第二个容器也无法使用它。

谢谢!

Dav*_*ert 2

由于这个原因,我更喜欢直接在主机上运行代理(haproxy 的 nginx)。

但一个选择是“通过大使容器链接” 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