Journeys · Docker · L1

A request to a published port

Two ways in to the same container. Which one your request takes depends on the address you use.

✓ Validated on Docker Engine 29.9.3 · Run 1 · 2026-11-20Preview

The 30-second answer

-p 8080:8080 makes dockerd do two things. It starts docker-proxy, a small program that listens on host port 8080 and opens its own connection to the container. And it writes NAT rules into the kernel that rewrite packets for port 8080 to the container's address. A request to localhost skips the rules and goes through docker-proxy. A request to the host's own address is rewritten by the kernel and reaches the container directly.

Mental model

A building with a front door and a mail chute. The doorman (docker-proxy) takes visitors from the front door and walks them to the flat himself. The mail chute (the NAT rule) sends letters addressed to the building straight down to the flat, with a new address label.

Where the analogy breaks

In a building you choose the door. Here the address you dial chooses for you. Requests to localhost never meet the NAT rule, so they always go through docker-proxy. The flat can tell them apart: visitors walked in by the doorman come from the network's gateway address.

🔒 Free account

Sign up free to play this journey

A free account unlocks every scenario, journey and exam, and saves your progress. No payment, ever.