我让它正常工作,但现在它停了。我尝试了以下命令,但没有效果:

Docker运行-dns 8.8.8.8 base ping google.com

Docker运行base ping google.com

Sysctl -w net.ipv4。Ip_forward =1 -在主机和容器上

我得到的是未知主机google.com。Docker 0.7.0版本

什么好主意吗?

P.S. ufw也被禁用了


当前回答

我在Ubuntu 18.04上遇到了这个问题。然而问题出在DNS上。我所在的公司网络有自己的DNS服务器,并阻止其他DNS服务器。这是为了阻止一些网站(色情,种子,…等等)

解决你的问题

在主机上查找您的DNS 建议使用——dns your_dns 由@jobin Docker run——dns your_dns -it——name cowsay——hostname cowsay debian bash

其他回答

在我的例子中,由于一些未知的原因,docker被配置为不生成网络所需的iptables规则容器。docker容器只能ping主机,没有其他功能。这里的大多数答案都没有帮助;重新创建桥或重新启动服务改变了任何东西。

但后来,在一次偶然的机会下,我发现了以下内容:

$ cat /etc/docker/daemon.json
{"iptables": false}

我删除了/etc/docker/daemon.文件Json并重新启动守护进程(默认是创建iptables规则)。这解决了网络问题。

下面是修复前的iptables规则:

$ iptables -L -n
Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy DROP)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

现在,iptables规则修复后:

$ iptables -L -n
Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy DROP)
target     prot opt source               destination
DOCKER-USER  all  --  0.0.0.0/0            0.0.0.0/0
DOCKER-ISOLATION-STAGE-1  all  --  0.0.0.0/0            0.0.0.0/0
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED
DOCKER     all  --  0.0.0.0/0            0.0.0.0/0
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED
DOCKER     all  --  0.0.0.0/0            0.0.0.0/0
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

Chain DOCKER (2 references)
target     prot opt source               destination
ACCEPT     tcp  --  0.0.0.0/0            172.17.0.2           tcp dpt:8443

Chain DOCKER-ISOLATION-STAGE-1 (1 references)
target     prot opt source               destination
DOCKER-ISOLATION-STAGE-2  all  --  0.0.0.0/0            0.0.0.0/0
DOCKER-ISOLATION-STAGE-2  all  --  0.0.0.0/0            0.0.0.0/0
RETURN     all  --  0.0.0.0/0            0.0.0.0/0

Chain DOCKER-ISOLATION-STAGE-2 (2 references)
target     prot opt source               destination
DROP       all  --  0.0.0.0/0            0.0.0.0/0
DROP       all  --  0.0.0.0/0            0.0.0.0/0
RETURN     all  --  0.0.0.0/0            0.0.0.0/0

Chain DOCKER-USER (1 references)
target     prot opt source               destination
RETURN     all  --  0.0.0.0/0            0.0.0.0/0

我在Ubuntu 18.04上遇到了这个问题。然而问题出在DNS上。我所在的公司网络有自己的DNS服务器,并阻止其他DNS服务器。这是为了阻止一些网站(色情,种子,…等等)

解决你的问题

在主机上查找您的DNS 建议使用——dns your_dns 由@jobin Docker run——dns your_dns -it——name cowsay——hostname cowsay debian bash

我在这里尝试了大部分答案,但唯一有效的是重新创建网络:

$ docker network rm the-network
$ docker network create --driver=bridge the-network

我还需要重新创建使用它的docker容器:

$ sudo docker create --name the-name --network the-network

然后是互联网接入。

对我来说,是主机的防火墙。我必须在主机的防火墙上允许DNS。并且在更改主机防火墙设置后不得不重新启动docker。

我试了所有的答案,没有一个对我有效。

在尝试了几个小时后,我找到了这个方法:

reboot

-_-