我让它正常工作,但现在它停了。我尝试了以下命令,但没有效果:
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也被禁用了
当前回答
对我来说,使用centos 7.4,这不是/etc/resolve.conf, iptables, iptables NAT规则或docker本身的问题。问题是主机缺少包bridge-utils, docker需要使用brctl命令来构建桥。Yum安装-y bridge-utils并重新启动docker,解决问题。
其他回答
当我的一个容器随机发生这种情况,而其他容器都很好时,我被难住了。容器至少连接到一个非内部网络,因此Compose定义没有任何问题。重启VM / docker守护进程没有帮助。这也不是DNS问题,因为容器甚至不能ping外部IP。为我解决这个问题的是重新创建docker网络。在我的例子中,docker-compose down && docker-compose up工作。
组成
这迫使我们重新构建所有容器的网络:
Docker-compose down && Docker-compose up
群模式
我认为你只是删除并重新创建服务,这将重新创建服务的网络:
Docker服务rm some-service
Docker服务创建…
如果容器的网络是外部的
只需删除并重新创建该服务的外部网络:
Docker网络rm some-external-network
Docker网络创建一些外部网络
其他回答指出,docker0接口(桥接)可能是问题的根源。在Ubuntu 20.04上,我观察到接口缺少它的IP地址(用IP addr show dev docker0检查)。仅仅重新启动Docker并没有帮助。我不得不手动删除桥接接口。
sudo ip link delete docker0
sudo systemctl restart docker
我使用的是Arch Linux,在尝试了以上所有的答案后,我意识到我的机器上启用了防火墙,nftables,并禁用它。我说:
sudo systemctl disable nftables
sudo systemctl stop nftables
sudo reboot
我的网卡:
➜ ~ ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp1s0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN mode DEFAULT group default qlen 1000
link/ether 68:f7:28:84:e7:fe brd ff:ff:ff:ff:ff:ff
3: wlp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DORMANT group default qlen 1000
link/ether d0:7e:35:d2:42:6d brd ff:ff:ff:ff:ff:ff
4: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default
link/ether 02:42:43:3f:ff:94 brd ff:ff:ff:ff:ff:ff
5: br-c51881f83e32: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default
link/ether 02:42:ae:34:49:c3 brd ff:ff:ff:ff:ff:ff
6: br-c5b2a1d25a86: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default
link/ether 02:42:72:d3:6f:4d brd ff:ff:ff:ff:ff:ff
8: veth56f42a2@if7: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP mode DEFAULT group default
link/ether 8e:70:36:10:4e:83 brd ff:ff:ff:ff:ff:ff link-netnsid 0
和我的防火墙配置,/etc/nftables.conf,我现在禁用了,将来会尝试改进,这样我就可以正确设置docker0网卡规则:
#!/usr/bin/nft -f
# vim:set ts=2 sw=2 et:
# IPv4/IPv6 Simple & Safe firewall ruleset.
# More examples in /usr/share/nftables/ and /usr/share/doc/nftables/examples/.
table inet filter
delete table inet filter
table inet filter {
chain input {
type filter hook input priority filter
policy drop
ct state invalid drop comment "early drop of invalid connections"
ct state {established, related} accept comment "allow tracked connections"
iifname lo accept comment "allow from loopback"
ip protocol icmp accept comment "allow icmp"
meta l4proto ipv6-icmp accept comment "allow icmp v6"
#tcp dport ssh accept comment "allow sshd"
pkttype host limit rate 5/second counter reject with icmpx type admin-prohibited
counter
}
chain forward {
type filter hook forward priority filter
policy drop
}
我不知道我在做什么,但这对我很有用:
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的方法不是手动,而是使用service或systemctl命令:
service docker restart
or
systemctl restart docker