How -p 8080:80 reaches your container
Select an icon to see what it is.
Step 6 of 6
The reply is translated back
nginx in web answers with a SYN-ACK from 172.18.0.2:80. Conntrack remembers the DNAT, so on the way out the kernel rewrites the source to 10.0.0.20:8080. The laptop only ever sees the host's address.
PrevNext
SYN-ACK leaves the container
172.18.0.2:80 -> 192.168.1.10:54321 flags=SYN,ACK
IPv4 · 20 B
Version 4b
4
IHL 4b
5 (20 B)
DSCP/ECN 8b
0
Total length 16b
40
Identification 16b
0x0000
Flags 3b
DF
Fragment offset 13b
0
TTL 8b
64
Protocol 8b
6 (TCP)
Header checksum 16b
0xcd09
Source IP 32b
172.18.0.2
Destination IP 32b
192.168.1.10
TCP (simplified: options omitted) · 20 B
Source port 16b
80
Destination port 16b
54321
Sequence number 32b
0x5e6f7a8b
Acknowledgment number 32b
0x1a2b3c4e
Data offset 4b
5 (20 B)
Reserved 3b
0
Flags 9b
SYN, ACK
Window 16b
64240
Checksum 16b
0x4325
Urgent pointer 16b
0
Try it yourself
Create the network, publish the port, and look at the rule Docker added.
$ docker network create --subnet 172.18.0.0/16 shop-net$ docker run -d --name web --network shop-net -p 8080:80 nginx$ docker port web$ sudo iptables -t nat -L DOCKER -n$ curl http://localhost:8080$ docker rm -f web$ docker network rm shop-net