问题原文
原帖链接 · 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 :)
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
