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.
More on Networking
What network drivers does Docker have?BeginnerHow does the default bridge network work?AdvancedDefault bridge vs user-defined bridge: what is the difference?IntermediateHow does container DNS work?IntermediateWhat is the difference between `-p 80:80` and `-p 127.0.0.1:80:80`?BeginnerHow does `--network host` work and what are the trade-offs?Intermediate