Concepts / Container networking

Container networking

Published port

Also called docker run -p, port publishing, port mapping, container port

A host port forwarded to a container's port with a DNAT rule, so others reach a container through its host.

The host rewrites the destination to the container
The host rewrites the destination to the container

A packet for the host's port 8080 has its destination changed to the container's address and port 80. Without a published port, nothing outside the host can start a connection to the container.

A published port is a host port forwarded to a port inside a container. Containers sit on a private bridge network behind their host's NAT: they reach out, nobody reaches in. docker run -p 8080:80 publishes one: the host gets a DNAT rule sending its port 8080 to the container's port 80, the same rewrite as a home router's port forward. -p 127.0.0.1:8080:80 publishes to the host alone.

See it on real machines

Read next

Learn it on real machines.

Every lab is a small network of real Linux machines in your browser. Sign in with Google or email to start.

Start this lab