无法连接到docker容器内的其他主机

时间:2018-03-07 13:15:50

标签: docker networking routing centos centos7

  

我解决了它,请在说明末尾进行编辑。

我使用Centos7作为主机并运行docker版本17.05.0-ce

我能够将图像拉到主机上。 从一个contiainer内部我能够ping到docker接口,我也能够ping主机。但就是这样,我无法ping任何其他主机,而不是本地网络上的DNS,不是谷歌,没有。我想这是路由的一部分,但我无法弄明白。 有人有个主意吗? 这显然不是关于连接到同一主机上的其他容器。但可能是docker中的路由或配置问题

jonmat ~ $ docker -v 
Docker version 17.05.0-ce, build 89658be

# pulling images works fine, so the engine can connect to the internet
jonmat ~ $ docker pull alpine
Using default tag: latest
latest: Pulling from library/alpine
ff3a5c916c92: Pull complete 
Digest: sha256:7b848083f93822dd21b0a2f14a110bd99f6efb4b838d499df6d04a49d0debf8b
Status: Downloaded newer image for alpine:latest

# pinging google dns from the host is is no problem
jonmat ~ $ ping -c1 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=56 time=5.16 ms

--- 8.8.8.8 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 5.160/5.160/5.160/0.000 ms

# pinging google dns from inside the container won't work, probably some kind of routing issue?
jonmat ~ $ docker run -it --rm alpine ping -c1 8.8.8.8
PING 8.8.8.8 (8.8.8.8): 56 data bytes

--- 8.8.8.8 ping statistics ---
1 packets transmitted, 0 packets received, 100% packet loss

编辑: 我自己发现了这个问题。除了我以外的其他人也一直在使用主机,并且他们添加了选项" - ptables = false"对于dockerd,我删除了它,它解决了我的问题。

2 个答案:

答案 0 :(得分:0)

假设您的容器以名称alpine运行,您可以尝试使用以下命令

docker exec -t alpine ping 8.8.8.8

答案 1 :(得分:0)

在上面给出的例子中,似乎你缺少一些选项,试试这个

docker run -it --rm -t alpine ping -c1 8.8.8.8

如果容器已在运行,请使用上面发布的docker exec。 (我想结合两个答案,但不幸的是我没有找到删除选项并将其添加到第一个答案中)

有关详细信息,请参阅docker exec

相关问题