解决docker和kvm网络冲突的问题

在一台kvm宿主机上安装了docker以后发现kvm的虚拟机无法获取到ip,配置静态ip网络也无法正常工作,但是宿主机的网络却很正,排查到libvirtd有如下报错

1
2
3
4
Apr 18 13:12:05 workspace libvirtd[721]: Failed to open file '/sys/class/net/vethaf21808/operstate': No such file or directory
Apr 18 13:12:05 workspace libvirtd[721]: unable to read: /sys/class/net/vethaf21808/operstate: No such file or directory
Apr 18 13:37:01 workspace libvirtd[721]: internal error: End of file from qemu monitor
Apr 18 13:37:25 workspace libvirtd[721]: internal error: End of file from qemu monitor

排查了一通没有更详细的消息,猜测是docker网桥导致的问题。于是查询到资料将docker网桥绑定到br0上面问题解决。操作如下

1
2
3
4
5
# vim /etc/docker/daemon.json
{
"bridge": "br0",
"default-gateway": "172.16.80.1" #此处ip地址为宿主机的真实网关
}

PS:
故障原因是docker server在启动的时候会创建docker网桥docker0,用于提供docker内部的网络通信以及容器和docker外界的通信。默认docker0会绑定物理网卡如enp0xxxeth0。而br0也绑定了物理网卡,docker0将物理网卡抢占,导致kvm使用br0无法正常获取网络。

0%