我有一个 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
启动了 nginx . webapp 容器 (humansio) 总是暴露 8080。
问题是,当我重新加载 webapp 容器时,nginx 容器的链接会中断,我也需要重新启动它。有什么办法可以不同地做到这一点,所以当 webapp 容器重新加载时我不需要重新启动 nginx 容器?
--
我尝试过使用公共(public)端口(两者都为 8001)手动连接它们,但由于它们实际上保留了该端口,因此第二个容器也无法使用它。
谢谢!
最佳答案
出于这个原因,我更喜欢直接在主机上运行代理(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
关于nginx - 使用 Docker 和 Nginx proxy_pass 时重启容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28824438/