Pcornel
Containers · Container Networking

Published Ports and Port Mapping

Cheat sheet · https://pcornel.dk/topic.php?topic=6131

Back to the Topic

Answer

Publishing ports maps a host port to a container port (-p 8080:80), implemented with NAT rules by Docker or hostPort/NodePort/LoadBalancer in Kubernetes.

Remember

The app must listen on 0.0.0.0 inside. Published ports may bypass host firewall rules (use DOCKER-USER). Binding to 127.0.0.1:8080:80 limits exposure to localhost.

First checks

  • docker ps -a — containers and exit codes
  • docker logs <c> — container output
  • docker inspect <c> — config, mounts, network, state

Verify in this order

client → host port → NAT → container port → app

Where it usually breaks

An app bound to 127.0.0.1 inside the container is unreachable even with the port published.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=6131

Confirmation

Confirm action

Continue?