7.3.1.2 Wrong Host Port
A focused guide to Wrong Host Port, connecting core concepts with practical Docker and container operations.
A wrong host port mistake occurs when attempting to reach a container at a port number that doesn't actually match its configured publishing — often the result of confusing which side of the host:container mapping is which, or simply trying a different port than was actually configured.
How This Mistake Typically Happens
The -p flag's mapping format places the host port first and the container port second; reversing this mental model, or simply misremembering which port was actually published, leads to attempting to connect at the wrong port.
docker run -d -p 3000:8080 myapp:1.0
curl http://localhost:8080
This fails, since 8080 was the container-side port, not the host-side port — the application is actually reachable at 3000, not 8080.
Confirming the Actual Published Mapping
Checking the actual, current port mapping directly resolves any confusion about which port should actually be used.
docker port myapp
8080/tcp -> 0.0.0.0:3000
This output clarifies that 3000 is the correct host-side port to use, regardless of what might have been assumed.
The Fix: Using the Correct Host Port
Connecting at the actual, confirmed host port resolves the issue.
curl http://localhost:3000
Avoiding This Mistake Going Forward
Using matching host and container port numbers, when there's no specific reason they need to differ, reduces the chance of this kind of confusion in future configuration and troubleshooting.
docker run -d -p 8080:8080 myapp:1.0
Why Recognizing the Wrong Host Port Mistake Matters
This is a simple, easily made mistake that produces a connection failure indistinguishable in symptom from several other possible causes — directly checking the actual configured mapping with docker port quickly rules in or out this specific, common explanation before investigating anything more complex.