Skip to content

How -p 8080:80 reaches your container

Select an icon to see what it is.

Step 3 of 6

dockerd adds the NAT rule

dockerd writes iptables rules in the nat table's DOCKER chain. Packets for host port 8080 get their destination rewritten to 172.18.0.2:80. By default it also starts a docker-proxy process for this port.

$ sudo iptables -t nat -L DOCKER -n

iptables -t nat (DOCKER chain; rule text varies by Docker version)

-A DOCKER ! -i br-<id> -p tcp -m tcp --dport 8080 -j DNAT --to-destination 172.18.0.2:80
-A DOCKER -d 172.18.0.2/32 ! -i br-<id> -o br-<id> -p tcp -m tcp --dport 80 -j ACCEPT (filter table)
docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8080 -container-ip 172.18.0.2 -container-port 80