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

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也被禁用了


当前回答

我使用的是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
  }

其他回答

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

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

reboot

-_-

唯一能在我的电脑上工作的东西(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

对于Ubuntu 19.04使用openconnect 8.3进行VPN,我必须将/etc/resolve.conf符号链接到systemd中的文件(与answerby wisbucky相反)

执行ln -sf /etc/resolv.conf /run/systemd/resolve/resolv.conf

调试步骤

连接到公司VPN 在/etc/resolv.conf或/run/systemd/resolve/resolv.conf中查找正确的VPN设置 无论哪个有正确的DNS设置,我们都会将其符号链接到另一个文件 (提示:在赋值的左边放置一个设置正确的)

Docker版本:Docker版本19.03.0-rc2,构建f97efcc

其他回答指出,docker0接口(桥接)可能是问题的根源。在Ubuntu 20.04上,我观察到接口缺少它的IP地址(用IP addr show dev docker0检查)。仅仅重新启动Docker并没有帮助。我不得不手动删除桥接接口。

sudo ip link delete docker0
sudo systemctl restart docker

用OSX的答案更新这个问题(使用Docker Machine)

如果你使用Docker Machine在OSX上运行Docker,那么下面的方法对我来说是有效的:

docker-machine restart

<...wait for it to restart, which takes up to a minute...>

docker-machine env
eval $(docker-machine env)

然后(至少在我的经验中),如果你从容器中ping google.com,一切都会很好。