Skip to main content

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.

flowchart TD subgraph host [Linux host] BR([Bridge docker0]) --- W[web 172.17.0.2] BR --- A[api 172.17.0.3] BR --- D[(db 172.17.0.4)] end BR -->|NAT| NET[Outside network] classDef c fill:#DBEAFE,color:#1E293B classDef n fill:#EDE9FE,color:#1E293B class W,A,D c class BR,NET n

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

Bash
# Create a user-defined bridge and attach containers
docker network create payment-network
docker run -d --name postgres --network payment-network \
-e POSTGRES_PASSWORD=devpassword postgres:16
docker run -d --name payment-api --network payment-network payment-api:v3.1.0
# Name resolution works on the user-defined network
docker exec payment-api getent hosts postgres
# Inspect and clean up
docker network inspect payment-network
docker network connect monitoring-network payment-api
docker network prune

Docker Compose creates a user-defined bridge per project automatically, so service names resolve with no extra setup.

Remember

Name resolution is the key difference. If DB_HOST=postgres fails with "not resolved", the containers are probably on the default bridge.

Security

Containers 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.

Found a mistake, an outdated step or a broken link?