我让它正常工作,但现在它停了。我尝试了以下命令,但没有效果:
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也被禁用了
我让它正常工作,但现在它停了。我尝试了以下命令,但没有效果:
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也被禁用了
当前回答
我试了所有的答案,没有一个对我有效。
在尝试了几个小时后,我找到了这个方法:
reboot
-_-
其他回答
如果你在OSX上,你可能需要在安装Docker后重新启动你的机器。这有时是一个问题。
对我来说,这是iptables的转发规则。由于某种原因,下面的规则,当与docker的iptables规则结合在一起时,导致所有来自容器的出站流量都到达localhost:8080:
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8080
iptables -t nat -I OUTPUT -p tcp -d 127.0.0.1 --dport 80 -j REDIRECT --to-ports 8080
唯一能在我的电脑上工作的东西(8.8.8.8不起作用)
找出本地机器中使用的DNS:
$ netstat -ntpl | grep :53
tcp 0 0 10.194.128.1:53 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN -
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN -
tcp 0 0 127.0.2.1:53 0.0.0.0:* LISTEN -
修改docker配置sudo vim /etc/docker/daemon.Json基于上述信息在您自己的计算机上
{
"dns": ["192.168.122.1","10.194.128.1"]
}
重启码头工人
sudo ip link delete docker0
sudo systemctl restart docker
对我来说,使用centos 7.4,这不是/etc/resolve.conf, iptables, iptables NAT规则或docker本身的问题。问题是主机缺少包bridge-utils, docker需要使用brctl命令来构建桥。Yum安装-y bridge-utils并重新启动docker,解决问题。
在我的例子中,由于一些未知的原因,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