大网数据广告活动
服务器运维问答

Docker breaks libvirt bridge network

· 52CE 我爱测

This issue is driving me crazy. I run a fresh install of Ubuntu 18.04, with: ufw to manage the firewall a br0 bridge lxd and libvirt (KVM) I tried stock docker.io package and packages form docker's own deb repository. I want o be…

问题原文

原帖链接 · Laurent · CC BY-SA 4.0

This issue is driving me crazy. I run a fresh install of Ubuntu 18.04, with:

  • ufw to manage the firewall
  • a br0 bridge
  • lxd and libvirt (KVM)

I tried stock docker.io package and packages form docker's own deb repository.

I want o be able to deploy docker containers choosing the ip to bind its port (eg. -p 10.58.26.6:98800:98800) and then open the port with UFW.

But docker seems to create iptables rules that pertubates the br0 bridge (eg. host cannot ping libvirt guests)

I have looked all around and cannot find good, security aware solution.

Manually doing iptables -I FORWARD -i br0 -o br0 -j ACCEPTseems to makes everything work.

Also setting "iptables": false for the docker daemon allows the bridge to behave normally, but breaks docker's containers egress network.

I have found this solution that seemed simple, by editing a single UFW's file https://stackoverflow.com/a/51741599/1091772, but it doesn't work at all.

What would be the best practice and secure way of solving this permanently, surviving to reboots ?

EDIT: I ended up adding -A ufw-before-forward -i br0 -o br0 -j ACCEPT at the end of /etc/ufw/before.rules before the COMMIT. Can I consider this as a fix or doesn't it raise some issues ?

社区高分解答

原帖链接 · Gerard de Leeuw · CC BY-SA 4.0

I fixed this issue by adding the following line to /usr/lib/systemd/system/docker.service:

[Service]
ExecStartPost=iptables -I DOCKER-USER -i br0 -o br0 -j ACCEPT

Note that I don't have to create the chain or check the existence of this rule, because Docker always clears the existing rules first and recreates the chain before running the ExecStartPost command. Many thanks to excellent explanation in https://serverfault.com/a/964491/979362 to figure this out :)

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-04-19)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。