[英]Docker - access another container on the same machine via its public ip, without docker links
On a VPS with a static, publicly routable IP, I have a simple web server running (on port 8080) in a container that exports port 8080 ( -p 0.0.0.0:8080:8080
). 在具有静态,可公共路由的IP的VPS上,我有一个运行在端口8080(
-p 0.0.0.0:8080:8080
)的容器中的简单Web服务器(在端口8080上)运行。
If I spin up another container on the same box and try to curl <public ip of host>:8080
it resolves the address, tries to connect but fails when making the request (it just hangs). 如果我在同一盒子上旋转另一个容器并尝试
curl <public ip of host>:8080
它将解析该地址,尝试连接,但在发出请求时失败(它只是挂起)。
From the host's shell (outside containers), curl <public ip of host>:8080
succeeds. 在主机的外壳(外部容器)中,
curl <public ip of host>:8080
成功。
Why is this happening? 为什么会这样呢? My feeling is that, somehow, the virtual network cards fail to communicate with each other.
我的感觉是,虚拟网卡无法以某种方式相互通信。 Is there a workaround (besides using docker links)?
是否有解决方法(除了使用docker链接)?
According to Docker's advanced networking docs ( http://docs.docker.io/use/networking/ ): "Docker uses iptables under the hood to either accept or drop communication between containers." 根据Docker的高级网络文档( http://docs.docker.io/use/networking/ ):“ Docker在幕后使用iptables来接受或丢弃容器之间的通信。”
As such, I believe you would need to setup inbound and outbound routing with iptables. 因此,我相信您需要使用iptables设置入站和出站路由。 This article gives a solid description of how to do so: http://blog.codeaholics.org/2013/giving-dockerlxc-containers-a-routable-ip-address/
本文对操作方法进行了详尽的描述: http : //blog.codeaholics.org/2013/giving-dockerlxc-containers-a-routable-ip-address/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.