Lesson 9 / 26

Exposing Ports

Map a container's internal port to a port on your host machine.

-p host:container

By default a container's network is isolated. -p 8080:80 forwards your host's port 8080 to the container's port 80.

docker run -d -p 8080:80 nginx
# visit http://localhost:8080 on your host

EXPOSE is just documentation

The Dockerfile's EXPOSE 80 instruction only documents the intended port — it doesn't actually publish it. You still need -p at run time.