✦ For everyone, free.

Practical knowledge for real and everyday life

Home

6.3.2.2 Host Port Bindings

A focused guide to Host Port Bindings, connecting core concepts with practical Docker and container operations.

Host port bindings are the host-side half of a port publishing mapping — the specific port number (and optionally, network interface) on the host machine through which a container's internal port becomes externally reachable.

Specifying a Host Port Binding

A host port binding pairs a host-side port with a container-side port, connecting external traffic on the host port to the application listening on the container port.

docker run -d -p 8080:80 nginx:alpine

Here, 8080 is the host port binding, while 80 is the container's internal port the application actually listens on.

Why Host Port Bindings Must Be Unique Per Host

Unlike internal container ports, which can be freely duplicated across separate containers, a specific host port can only be bound to one container at a time — attempting to bind an already-used host port fails.

docker run -d -p 8080:80 app-a:1.0
docker run -d -p 8080:80 app-b:1.0

The second command fails, since host port 8080 is already bound by the first container.

Binding to a Specific Network Interface

A host port binding can be restricted to a specific network interface, limiting exactly where on the host the mapping is actually reachable from.

docker run -d -p 192.168.1.10:8080:80 myapp:1.0

This binds only to the specified interface's address, rather than every interface on the host.

Inspecting Active Host Port Bindings

Currently active host port bindings for a running container can be inspected directly.

docker port myapp
Why Understanding Host Port Bindings Matters

A clear understanding of host port bindings — including their host-wide uniqueness constraint and optional interface restriction — is essential for correctly avoiding port conflicts and for deliberately controlling exactly how and where a containerized service becomes reachable from the host's network.