Filed under · Docker · 2026-07-05 · 4 min read
Ports in Docker without the confusion
The mapping 3000:8080 looks simple, but it can be confusing when you're new to Docker. The easiest way I remember it is HOST : CONTAINER. Port 3000 on my machine forwards traffic to port 8080 inside the container.
Example
yamlservices:
web:
build: .
ports:
- "3000:8080"If the application inside the container listens on port 8080, I can open http://localhost:3000 from my computer. Docker forwards that traffic to port 8080 inside the container.
The application still has to listen correctly
Port publishing cannot fix an application that listens on the wrong internal port. If the application listens on 8080, the container side of the mapping needs to point to 8080.
Container-to-container traffic is different
Two containers on the same Compose network usually communicate using their service names and container ports—for example, api:8080—rather than going through localhost:3000.
Read Docker port mappings from left to right: host first, container second.