Publishing Ports

Port Mapping

A container has its own network stack. To reach it from your machine, publish a port with -p HOST:CONTAINER.

OptionEffect
-p 8080:80host port 8080 → container port 80 on all interfaces
-p 127.0.0.1:8080:80only reachable from this machine
-p 80a random free host port (see docker port)

Note: Inside the container, the app must listen on 0.0.0.0, not 127.0.0.1, or published ports will not reach it.

Check the Mapping

Example

docker port web

Example output

80/tcp -> 0.0.0.0:8080