我让它正常工作,但现在它停了。我尝试了以下命令,但没有效果:
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也被禁用了
当前回答
如果你在OSX上,你可能需要在安装Docker后重新启动你的机器。这有时是一个问题。
其他回答
我不知道我在做什么,但这对我很有用:
OTHER_BRIDGE=br-xxxxx # this is the other random docker bridge (`ip addr` to find)
service docker stop
ip link set dev $OTHER_BRIDGE down
ip link set dev docker0 down
ip link delete $OTHER_BRIDGE type bridge
ip link delete docker0 type bridge
service docker start && service docker stop
iptables -t nat -A POSTROUTING ! -o docker0 -s 172.17.0.0/16 -j MASQUERADE
iptables -t nat -A POSTROUTING ! -o docker0 -s 172.18.0.0/16 -j MASQUERADE
service docker start
在我的例子中,由于一些未知的原因,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
在windows(8.1)我杀死了virtualbox接口(通过任务管理),它解决了这个问题。
对我来说,我的问题是没有安装iptables-services,这对我来说是有效的(CentOS):
sudo yum install iptables-services
sudo service docker restart
最初我的docker容器能够连接到外部互联网(这是一个运行在Amazon EC2上的docker服务/容器)。
由于我的应用程序是一个API,我随后创建了我的容器(它成功地拉出了所需的所有包),更新了我的IP表,将所有流量从端口80路由到端口,我的API(在docker上运行)正在监听。
后来,当我试图重建容器时,它失败了。经过一番努力,我发现我的上一个步骤(设置IPTable端口转发规则)搞乱了docker的外部网络功能。
解决方案:停止IPTable服务:
Sudo服务iptables停止
重启Docker守护进程:
Sudo服务docker重启
然后,尝试重新构建容器。希望这能有所帮助。
跟进
我完全忽略了一点,我不需要打乱IP表,就可以将进入的流量转发到80,到运行在docker上的API正在运行的端口。相反,我只是将端口80别名为docker中API正在运行的端口:
Docker运行-d -p 80:<api_port> <image>:<tag> <command to start api>