Bridge Network
A bridge network is Docker's default single-host network driver, which connects containers through a virtual Linux bridge with NAT to the outside. User-defined bridge networks add automatic DNS by container name.
How a bridge network works
On Linux, Docker creates a virtual switch called a bridge (docker0 for the default network, br-<id> for user-defined ones). Each container gets a veth pair: one end inside the container as eth0, the other plugged into the bridge. iptables rules provide outbound NAT, and -p publishing adds inbound DNAT rules.
Default bridge versus user-defined bridge
- Default bridge: every container joins it unless told otherwise. There is no name resolution, only IPs, and IPs can change on restart.
- User-defined bridge: created with
docker network create. It has an embedded DNS server, so containers reach each other by name, and you get better isolation between apps.
Working with bridge networks
# Create a user-defined bridge and attach containersdocker network create payment-networkdocker run -d --name postgres --network payment-network \ -e POSTGRES_PASSWORD=devpassword postgres:16docker run -d --name payment-api --network payment-network payment-api:v3.1.0 # Name resolution works on the user-defined networkdocker exec payment-api getent hosts postgres # Inspect and clean updocker network inspect payment-networkdocker network connect monitoring-network payment-apidocker network pruneDocker Compose creates a user-defined bridge per project automatically, so service names resolve with no extra setup.
RememberName resolution is the key difference. If
DB_HOST=postgresfails with "not resolved", the containers are probably on the default bridge.
SecurityContainers on one bridge can talk to each other on any port. Put services that should not communicate on separate networks.
Frequently Asked Questions
Why does Docker recommend user-defined bridges over the default bridge?
User-defined bridges include an embedded DNS server that resolves container names to current IPs, plus better isolation and the ability to attach or detach containers live. The default bridge only supports IP-based access or the legacy --link flag.
Does publishing a port with -p expose it only to localhost?
No. By default -p 8080:80 binds to all host interfaces (0.0.0.0). Use -p 127.0.0.1:8080:80 when only local processes should reach it.
Can containers on different bridge networks talk to each other?
Not by default. They are isolated unless a container is connected to both networks with docker network connect, or you route through a published port on the host.