同一网络中的码头容器不能到达同一网络中的其他容器 [英] docker container in same network cannot reach other container in same network
问题描述
我使用 ubuntu 15.10
在数字海洋
以下作品
docker network创建一个
docker run -d --name = nginx --net =一个nginx
docker run -it --net = a --name web node bash
apt-get install -yq curl&& curl nginx
相反的是,尝试从$ $中获取 web容器
c $ c> nginx容器,不适合我。
The opposite, trying to reach the web container
from the nginx container
, does not work for me.
我进入网络容器:
docker exec -it web bash
然后我添加我的 index.html
文件
然后我使用 http-server
来提供 index.html
文件,命令为 http-server ./ -p 4200 -a 0.0.0.0 index.html
。
Then I use http-server
to serve an index.html
file with the command http-server ./ -p 4200 -a 0.0.0.0 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)无法连接到Web端口4200:拒绝连接
If I then go into nginx
and try curl web:4200
then I get curl: (7) Failed to connect to web port 4200: Connection refused
推荐答案
旋转一个新鲜的Ubuntu 15.10液滴数字海洋和
试图重现这一点;
Spun up a fresh Ubuntu 15.10 droplet on DigitalOcean and trying to reproduce this;
使用quick n dirty curl | sh
安装方法 - 不是最佳实践,但是很简单:
Using the quick n dirty curl | sh
install method - not best practice, but heck, it's easy:
apt-get install -y curl && curl -fsSL https://get.docker.com | sh
创建网络 mynetwork
和容器<$该网络上的c $ c> weba 和 webb
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
Reach webb from inside weba
docker exec -it weba sh -c 'curl http://webb:4200'
# welcome to webb
从webb内部到达weba
Reach weba from inside webb
docker exec -it webb sh -c 'curl http://weba:4200'
# welcome to weba
这看起来对我有用;你的环境有什么不同吗?
That looks to work for me; is there anything different on your environment?
这篇关于同一网络中的码头容器不能到达同一网络中的其他容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!