Port Mapping Basics
bash
1# Map host:container
2docker run -p 8080:80 nginx
3# │ └── Container port
4# └─────── Host portMultiple Ports
bash
1docker run -p 8080:80 -p 8443:443 nginxAll Interfaces vs Specific
bash
1# All interfaces (0.0.0.0)
2docker run -p 8080:80 nginx
3
4# Specific interface
5docker run -p 127.0.0.1:8080:80 nginx
6
7# Random host port
8docker run -p 80 nginx
9docker port mycontainer # See assigned portUDP Ports
bash
1docker run -p 53:53/udp dns-serverView Port Mappings
bash
1# List all port mappings
2docker port mycontainer
3
4# Specific port
5docker port mycontainer 80Expose vs Publish
dockerfile
1# Dockerfile - document port (no mapping)
2EXPOSE 80
3
4# Run - actually publish
5docker run -p 8080:80 myimage