Port Mapping (-p flag)
LEVEL 0
The Problem
You start a container running nginx:
docker run -d nginx
Nginx is listening on port 80 inside the container.
But when you try to access it from your browser at http://localhost:80, nothing happens.
Why? Because port 80 inside the container is not the same as port 80 on your host.
The container’s port 80 is in its own network namespace. It’s like a phone in a soundproof room—it’s ringing, but nobody outside can hear it.
How do you make the container’s port accessible from the outside?