The Bridge Network

The bridge driver creates a private internal network on the host so containers can communicate while staying isolated.

Syntaxdocker network create NETWORK_NAME

The bridge network is Docker's default driver. It creates a private virtual network on the host and connects containers to it.

Default vs custom bridge

The built-in bridge network works, but containers on it can only reach each other by IP address. A user-defined bridge network adds automatic DNS, so containers can find each other by name — which is what you almost always want.

Isolation with connectivity

The bridge keeps containers on a private network separate from the host, while still letting them talk to each other and, through published ports, to the outside world.

Example

Example · bash
# Create a user-defined bridge network
docker network create app-net

# Run containers attached to it
docker run -d --name db --network app-net postgres:16
docker run -d --name api --network app-net myapi:1.0

When to use it

  • Two containers on the same user-defined bridge network communicate by container name, acting as simple DNS-resolved hostnames.
  • A team isolates a group of containers on their own bridge network so they cannot reach containers on a different bridge.
  • A developer uses the default bridge network for quick local tests but switches to a user-defined bridge for a compose project.

More examples

Run containers on default bridge

Shows that containers on the default bridge must use IP addresses, not names, to reach each other.

Example · bash
docker run -d --name c1 alpine sleep 3600
docker run -d --name c2 alpine sleep 3600
# Containers share the default bridge but cannot reach each other by name
docker exec c1 ping -c2 $(docker inspect c2 --format '{{.NetworkSettings.IPAddress}}')

Create a user-defined bridge

User-defined bridge networks automatically enable DNS resolution by container name.

Example · bash
docker network create mybridge
docker run -d --name app --network mybridge myapp:latest
docker run -d --name db  --network mybridge postgres:16-alpine
# Now app can reach db by name
docker exec app ping -c2 db

Inspect containers on a bridge

Lists all containers attached to the bridge network along with their IP addresses.

Example · bash
docker network inspect mybridge \
  --format '{{range .Containers}}{{.Name}}: {{.IPv4Address}}\n{{end}}'

Discussion

  • Be the first to comment on this lesson.