网络无法在Docker/Centos 7.9上工作



我在Centos 7.9.2009上运行Docker,遇到了一个非常奇怪的问题。容器没有网络访问权限,无法从主机访问。我已经搜索了潜在的解决方案,其中很多似乎与DNS问题有关(我不认为这是这里发生的事情,因为即使从容器中ping 8.8.8.8也不起作用(。我试着安装了iptables服务,重新启动了iptables&docker的顺序,完全重新启动等

在我试图找出问题所在的过程中,我在一个单独的终端中运行了tcpdump。我一做,一切都很好!杀死tcpdump进程,它就会全部停止——没有网络访问。为什么运行tcpdump可以解决问题,有什么建议吗?这与tcpdump监听docker0并建立网络状态有关吗?

tcpdump启动时的输出:

tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on docker0, link-type EN10MB (Ethernet), capture size 262144 bytes

uname-a的输出:

Linux 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

/etc/redhat发布的输出:

CentOS Linux release 7.9.2009 (Core)

ip地址输出:

3: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:8b:94:46:19 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
valid_lft forever preferred_lft forever
inet6 fe80::42:8bff:fe94:4619/64 scope link
valid_lft forever preferred_lft forever

iptables的输出--list-t nat:

Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination
DOCKER     all  --  anywhere             anywhere             ADDRTYPE match dst-type LOCAL
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
DOCKER     all  --  anywhere            !loopback/8           ADDRTYPE match dst-type LOCAL
Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination
MASQUERADE  all  --  172.17.0.0/16        anywhere
Chain DOCKER (2 references)
target     prot opt source               destination
RETURN     all  --  anywhere             anywhere

docker版本的输出:

Client: Docker Engine - Community
Version:           19.03.13
API version:       1.40
Go version:        go1.13.15
Git commit:        4484c46d9d
Built:             Wed Sep 16 17:03:45 2020
OS/Arch:           linux/amd64
Experimental:      false
Server: Docker Engine - Community
Engine:
Version:          19.03.13
API version:      1.40 (minimum version 1.12)
Go version:       go1.13.15
Git commit:       4484c46d9d
Built:            Wed Sep 16 17:02:21 2020
OS/Arch:          linux/amd64
Experimental:     false
containerd:
Version:          1.3.7
GitCommit:        8fba4e9a7d01810a393d5d25a3621dc101981175
runc:
Version:          1.0.0-rc10
GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
docker-init:
Version:          0.18.0
GitCommit:        fec3683

提前感谢!

tcpdump开始列出一个接口时,它会将该接口置于混杂模式
这就是容器网络开始工作的直接原因。

通常docker0不需要混杂模式来工作
您所描述的行为表示网络堆栈中存在问题。

首先,您的Linux内核相当陈旧
3.10.0-327版本由Redhat于2015年发布
检查此问题-看起来完全是同一个问题
作者通过内核升级和br_netfilter模块修复成功地解决了这个问题。

此外,在其他一些情况下(一、二(,只需删除接口和重新启动Docker就可以了
但我认为您仍然需要升级内核——它真的太旧了。

最新更新