0

I wanted docker to respect ufw rules, so found this topic https://stackoverflow.com/questions/30383845/what-is-the-best-practice-of-docker-ufw-under-ubuntu

I did the following:

set "iptables": false for docker,

set sed -i -e 's/DEFAULT_FORWARD_POLICY="DROP"/DEFAULT_FORWARD_POLICY="ACCEPT"/g' /etc/default/ufw

set iptables -t nat -A POSTROUTING ! -o docker0 -s 172.17.0.0/16 -j MASQUERADE

And it works, but I don't understand how traffic gets to the container?

Before sudo iptables-save | grep 8123 gave me:

-A POSTROUTING -s 172.21.0.5/32 -d 172.21.0.5/32 -p tcp -m tcp --dport 8123 -j MASQUERADE
-A DOCKER ! -i br-cf80e85bf468 -p tcp -m tcp --dport 8123 -j DNAT --to-destination 172.21.0.5:8123
-A DOCKER -d 172.21.0.5/32 ! -i br-cf80e85bf468 -o br-cf80e85bf468 -p tcp -m tcp --dport 8123 -j ACCEPT

But after I disable iptable there is no rules, how traffic comes to the docker 8123 then? Here 8123 docker published port 0.0.0.0:8123->8123/tcp

7
  • sudo fuser 8123/tcp?
    – A.B
    Commented Sep 26, 2020 at 10:34
  • 1
    What is your OS? Some distributions configure the dockerd to run communications over a different PID (docker-proxy) so it won't mess up with ufw (and that's why sometimes communications are slower for no reason). This UFW answer you're based seems to contain old info about the inner workings of docker. Commented Sep 26, 2020 at 15:22
  • @A.B 8123/tcp: 1420
    – ogbofjnr
    Commented Sep 26, 2020 at 17:41
  • @GustavoKawamoto, I'm on ubuntu 18.04. It is confirmed that docker mess up with ufw in my case, since ufw disable rules don't make and effect. But before and after disabling iptables for docker process listening for port is docker-proxy.
    – ogbofjnr
    Commented Sep 26, 2020 at 17:44
  • 1420 is likely docker-proxy's pid which Gustavo is talking about: here in case no iptables rule handles it.
    – A.B
    Commented Sep 26, 2020 at 17:48

0

You must log in to answer this question.

Browse other questions tagged .