同一networking中的docker集装箱无法到达同一networking中的其他集装箱

我在digital ocean上使用ubuntu 15.10

下面的工程docker network create a

docker run -d --name=nginx --net=a nginx

docker run -it --net=a --name web node bash

apt-get install -yq curl && curl nginx

相反,试图从nginx container到达web container nginx container ,对我来说不起作用。

我进入Web容器: docker exec -it web bash

然后我添加我的index.html文件

然后,我使用http-server通过命令http-server ./ -p 4200 -a 0.0.0.0 index.html来提供index.html文件。

http-server返回:

 Starting up http-server, serving ./ Available on: http:127.0.0.1:4200 http:172.17.0.5:4200 Hit CTRL-C to stop the server 

如果我然后进入nginx并尝试curl web:4200然后我得到curl: (7) Failed to connect to web port 4200: Connection refused

在DigitalOcean上创build一个新的Ubuntu 15.10液滴,并试图重现这一点;

使用快速的肮脏的curl | sh curl | sh安装方法 – 不是最佳实践,但是,很简单:

 apt-get install -y curl && curl -fsSL https://get.docker.com | sh 

在该networking上创buildnetworkingmynetwork和容器webawebb ;

 docker network create mynetwork docker run --net mynetwork --name weba -d node sh -c 'npm install http-server -g && mkdir -p /public && echo "welcome to weba" > /public/index.html && http-server -a 0.0.0.0 -p 4200' docker run --net mynetwork --name webb -d node sh -c 'npm install http-server -g && mkdir -p /public && echo "welcome to webb" > /public/index.html && http-server -a 0.0.0.0 -p 4200' 

从weba内部到达webb

 docker exec -it weba sh -c 'curl http://webb:4200' # welcome to webb 

从webb内部到达weba

 docker exec -it webb sh -c 'curl http://weba:4200' # welcome to weba 

这看起来对我有用; 你的环境有什么不同吗?

现在是时候质疑networking隔离是你使用容器的一个重要部分。

考虑通过在与主机操作系统相同的networking上运行容器来避免此问题。

在运行systemd现代Linux系统上,您可以访问systemd-nspawn容器解决scheme,而无需安装任何其他软件。 它提供进程隔离,资源pipe理,chroot环境以及使用–network-veth选项共享主机操作系统networking的能力。