How does `docker run -p` interact with `ufw`?

AdvancedConceptNetworking
Answer

Docker inserts its own iptables rules ahead of UFW's, so ufw deny 8080 does not block published ports. Fix by binding to 127.0.0.1, adding rules to the DOCKER-USER chain (which Docker never overwrites), or setting "iptables": false (then you manage NAT yourself).

iptables -I DOCKER-USER -i eth0 ! -s 10.0.0.0/8 -p tcp --dport 8080 -j DROP
All Docker questions Roadmap: Docker & containers

More on Networking