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

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 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

其他回答

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

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

reboot

-_-

在我的例子中,由于一些未知的原因,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

通过以下建议修复:

[…你能试着重置一切吗?

pkill docker
iptables -t nat -F
ifconfig docker0 down
brctl delbr docker0
docker -d

它将迫使docker重新创建网桥并重新执行所有网络规则

https://github.com/dotcloud/docker/issues/866#issuecomment-19218300

似乎界面以某种方式“挂起”。

更新docker的最新版本:

上面的答案可能仍然可以帮你完成工作,但自从这个答案发布以来已经有很长一段时间了,docker现在更加完善了,所以在使用iptables和所有东西之前,一定要先尝试这些。

Sudo service docker restart或者(如果你的Linux发行版没有使用upstart) Sudo systemctl restart docker

如果你运行的Docker是无根的,并且遇到了这个问题,在安装过程中,iptables可能没有正确配置,主要是因为在Docker抱怨iptables时使用了——skip-iptables选项:

[ERROR] Missing system requirements. Run the following commands to
[ERROR] install the requirements and run this tool again.
[ERROR] Alternatively iptables checks can be disabled with --skip-iptables .

########## BEGIN ##########
sudo sh -eux <<EOF
# Load ip_tables module
modprobe ip_tables
EOF
########## END ##########

让我们检查一下这是否是问题所在:是否加载了ip_tables内核模块?

sudo modprobe ip_tables

如果没有输出,这个答案可能对您没有帮助(无论如何您都可以尝试)。否则,输出如下所示:

modprobe: FATAL: Module ip_tables not found in directory /lib/modules/5.18.9-200.fc36.x86_64

让我们来解决它!

首先,卸载Docker rootless(不需要通过systemctl停止服务,脚本会处理):

dockerd-rootless-setuptool.sh uninstall --skip-iptables

确保安装了iptables包,尽管它是由主要发行版默认提供的。

现在,让ip_tables模块对modprobe可见并安装它(多亏了这个):

sudo depmod
sudo modprobe ip_tables

现在,重新安装Docker rootless:

dockerd-rootless-setuptool.sh install

如果它不打扰iptables,你就完成了,问题应该得到解决。不要忘记启用服务(即systemctl enable——user——now docker)!

重启docker的方法不是手动,而是使用service或systemctl命令:

service docker restart

or

systemctl restart docker