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

无法连接到docker容器内的其他主机,docker,networking,routing,centos,centos7,Docker,Networking,Routing,Centos,Centos7,我解决了它,在描述的末尾进行了编辑 我使用Centos7作为主机,运行docker版本17.05.0-ce 我可以把图像上传到主机上。 在contiainer中,我可以ping docker接口,也可以ping主机。但就是这样,我不能ping任何其他主机,不能ping本地网络上的dns,不能ping谷歌,什么也不能ping。我想是路线问题,但我想不出来。 有人有主意吗? 这(显然)与连接到同一主机上的其他容器无关。但可能是docker中的路由或配置问题 jonmat ~ $ docker -v

我解决了它,在描述的末尾进行了编辑

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

我可以把图像上传到主机上。 在contiainer中,我可以ping docker接口,也可以ping主机。但就是这样,我不能ping任何其他主机,不能ping本地网络上的dns,不能ping谷歌,什么也不能ping。我想是路线问题,但我想不出来。 有人有主意吗? 这(显然)与连接到同一主机上的其他容器无关。但可能是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
编辑:
我自己发现了问题。除我之外的其他人也在使用主机,他们向dockerd添加了选项“-ptables=false”,我删除了该选项,解决了我的问题。

假设您的容器运行的名称为alpine,您可以尝试下面的命令吗

docker exec -t alpine ping 8.8.8.8

在上面给出的示例中,您似乎缺少一些选项,请尝试以下操作

docker run -it --rm -t alpine ping -c1 8.8.8.8
如果容器已经在运行,请使用上面发布的docker exec。(我想合并两个答案,但不幸的是,我找不到在第一个答案中删除并添加它的选项)


有关更多详细信息,请参阅

这是所需的行为。创建docker网络并将容器连接在一起。请阅读理解。或者使用
docker compose
创建堆栈(它将为您创建一个docker网络)。不,这不是所需的行为,我不尝试在容器之间连接,而是与docker主机之外的主机连接。我已经编辑了这些示例,希望现在更清楚。@JonasMattsson您解决了这个问题吗?Centos新安装的docker具有以下功能problem@idchlife是的,我做了,阅读问题的结尾,解释我如何解决这个问题的发现。我不认为伪终端会帮助解决我的路由问题。我不明白为什么psudo终端会帮助我?