Ad space (banner)
AD

Got the fundamentals? A structured Docker course is a fast way to level up.

Find Docker courses on Udemy

Affiliate link. Costs you nothing extra.

🐳Docker Lessons
Lesson 17 / 45

Publishing a Port with docker run -p

When you want to reach a container's web server from your browser, use -p. It maps a port on the host to a port inside the container.

The syntax is docker run -p host-port:container-port image. The left side is your machine, the right side is inside the container.

Running docker run -p 8080:80 nginx forwards localhost:8080 on your machine to port 80 inside the container, so the site becomes reachable in a browser.

A common stumble is getting the order backwards. Host comes first, container second — swapping them is the classic reason "I can't reach it."

In real work, it is how you expose an application running in a container to the outside world.

Docker
Try it (type this into the pseudo terminal)
docker run -p 8080:80 nginx

🧑‍💻 You can type this command into the Docker pseudo terminal to try it yourself (this page itself has no interactive terminal).

Ad space (banner)
Ad space (in-article)