Card 03/ 06

GotchaDifficulty: Beginner1 min

Which Number in `-p 8080:80` Is Yours

The container is running, docker ps says so, and the browser says the connection was refused. Nothing is broken. The two numbers are the wrong way round.

bash
$ docker run -d -p 80:8080 nginx
$ curl localhost:8080
curl: (7) Failed to connect to localhost port 8080 after 0 ms: Couldn't connect to server

-p reads host first, container second. The command above asked the host to listen on 80 and forward to port 8080 inside the container, where nothing is listening, because nginx serves on 80.

Reading the pair
-p 8080:80Means
8080The port on your machine. This is the one you type in the browser
80The port the program inside the container is listening on

Reversed, it usually fails quietly rather than loudly: the host really does open the port you named, so docker ps looks correct and only the connection fails.