7.2.1.5 Bridge Port Publishing
A focused guide to Bridge Port Publishing, connecting core concepts with practical Docker and container operations.
Bridge port publishing is the use of docker run -p to make a specific container's port reachable from the host, applicable to containers on any bridge network (default or user-defined) and serving as the mechanism that bridges the network's otherwise contained traffic to the broader host and external network.
How Publishing Works on a Bridge Network
Port publishing configures the host to forward incoming traffic on a specified host port to a specific container's internal port, regardless of which bridge network that container happens to be attached to.
docker network create app-network
docker run -d --name api --network app-network -p 8080:8080 myapi:1.0
This makes api's internal port 8080 reachable on the host at port 8080, despite api being on a user-defined bridge network rather than the default one.
Publishing Works the Same Way Regardless of Network
The mechanics of port publishing don't differ between the default bridge network and a user-defined one — the only meaningful difference between the two networks concerns container-to-container name resolution, not how publishing itself functions.
docker run -d -p 8080:80 nginx:alpine
docker network create mynet
docker run -d --network mynet -p 8081:80 nginx:alpine
Both of these containers' published ports work identically, despite one using the default network and the other a user-defined one.
Combining Publishing With Internal Network Communication
A container's published port for external access and its internal network communication with other containers are independent and can coexist without conflict.
docker run -d --name api --network app-network -p 8080:8080 myapi:1.0
docker run -d --name db --network app-network postgres:16
api is both externally reachable (via its published port) and able to communicate internally with db (via the shared network), serving two distinct purposes simultaneously.
Why Bridge Port Publishing Matters
Understanding that port publishing operates consistently across both default and user-defined bridge networks clarifies that switching to a user-defined network for its name-resolution benefits requires no change to how external port publishing is configured or behaves.