Port mapping

2 snippets in Docker

DKDocker

Show Port Mappings

DK · Containers
syntax
docker port <container>
example
docker port web-api
output
3000/tcp -> 0.0.0.0:3000
8443/tcp -> 0.0.0.0:8443

Note Only shows ports explicitly published with -p at run time. Ports declared with EXPOSE in the Dockerfile are not listed here unless they were also published.

Port Mapping (-p)

DK · Run Options
syntax
docker run -p <host_port>:<container_port> <image>
docker run -p <host_ip>:<host_port>:<container_port> <image>
example
docker run -d -p 8080:3000 myapp:1.0
docker run -d -p 127.0.0.1:5432:5432 postgres:16

Note The format is always host:container. Binding to 127.0.0.1 restricts access to localhost only — critical for databases you do not want exposed on the network. Without an IP, Docker binds to 0.0.0.0 (all interfaces).