How does `-p 8080:80` work under the hood?

AdvancedConceptNetworking
Answer

Docker adds an iptables DNAT rule in the DOCKER chain of the nat table (host:8080 to container IP:80) plus filter rules to accept it, and by default runs a docker-proxy userland process for localhost/hairpin cases. Inspect with iptables -t nat -L DOCKER -n. Published ports bypass UFW/firewalld input rules, a frequent security surprise.

All Docker questions Roadmap: Docker & containers

More on Networking