Stage 3 · Network internals · Chapter 13 of 20 · 6 min read

Default bridge and veth pairs

The default bridge is a virtual switch on your host. Containers plug into it with virtual cables called veth pairs.

? What do the diagram colours mean

key idea / Docker itselfcontainer / good pathhost / watch outproblem / blockedneutral

The picture to remember

The default bridge networkTwo containers each have an eth0 connected by a veth pair to docker0, a virtual switch on the host. The host eth0 connects docker0 to the internet through NAT.InternetDocker hosthost eth0192.168.1.20NAT / routingdocker0 bridge 172.17.0.1a virtual switch: forwards by MAC addressContainer Aeth0 172.17.0.2veth pair (vethA)Container Beth0 172.17.0.3veth pair (vethB)
docker0 is a virtual switch. Each veth pair is the cable between a container and that switch.

A packet from A to B

A packet from A to BA eth0172.17.0.2vethAhost enddocker0looks up B's MACvethBhost endB eth0172.17.0.3
The bridge is a layer-2 switch, so it forwards on MAC address: no routing needed.

Why names fail here

You met the symptom in chapter 9 and the fix in chapter 10: on the default bridge, ping a fails while ping 172.17.0.2 works. Now that you can see the bridge, here is the mechanism.

Why does ping a fail?

The ping never leaves b. Before it can send a packet, it has to turn the name a into an IP address, and on the default bridge nothing can do that.

  1. b checks its own /etc/hosts. Docker writes only b itself and localhost there. There is no line for a.
    $ docker exec b cat /etc/hosts
    127.0.0.1    localhost
    172.17.0.3   3f1c2a9b7d10   # b only, no a
  2. b asks the DNS servers in /etc/resolv.conf. On the default bridge, Docker copies these from the host, so they are your normal network's DNS servers (your router, your ISP, or a public one). They have never heard of a container called a.
    $ docker exec b cat /etc/resolv.conf
    nameserver 192.168.1.1   # the host's DNS

    The exact address depends on your host. On Docker Desktop it is the VM's DNS proxy, which also does not know container names on this network.

  3. The lookup fails, so ping gives up. bad address 'a' is how BusyBox ping (the one in Alpine) says “I could not resolve this name”. No packet was sent, so docker0 never saw anything.

Why does the IP version work? An IP address needs no lookup. The packet goes straight to docker0, which forwards it by MAC address, as in the diagram above.

Why are there no names on this network? Docker has its own DNS server that answers with container names. Inside a container it lives at 127.0.0.11. It only serves user-defined networks. The default bridge is a legacy network and never got this feature.

Default bridgeUser-defined bridge
nameserver in resolv.confthe host's DNS127.0.0.11 (Docker DNS)
ping abad address 'a'works
a restarts with a new IPhard-coded IPs breakthe name follows the new IP

The fix, from chapter 10:

$ docker network create mynet
$ docker run -d --name a --network mynet --rm alpine:3.20 sleep 300
$ docker run -d --name b --network mynet --rm alpine:3.20 sleep 300
$ docker exec b cat /etc/resolv.conf
nameserver 127.0.0.11
$ docker exec b ping -c 1 a
64 bytes from 172.18.0.2: seq=0 ttl=64 time=0.1 ms

The old --link a flag also makes the name work, by writing a into b's /etc/hosts. It is deprecated, and that line goes stale when a's IP changes.

See it yourself

On Linux. On Docker Desktop these live inside the Linux VM.

Run thisIt shows
ip addr show docker0the bridge and its IP (172.17.0.1)
ip linkone vethXXXX per running container
docker inspect -f '{{.NetworkSettings.IPAddress}}' athe container's address on the bridge
docker exec b ip routedefault via 172.17.0.1: the gateway is docker0

Try it yourself

  1. Step 1 · Two containers on the default bridge

    Leaving off --network attaches them to bridge (docker0).

    $ docker run -d --name a --rm alpine:3.20 sleep 300
    $ docker run -d --name b --rm alpine:3.20 sleep 300
    $ docker inspect -f '{{.NetworkSettings.IPAddress}}' a
    172.17.0.2
    $ docker inspect -f '{{.NetworkSettings.IPAddress}}' b
    172.17.0.3
  2. Step 2 · Ping the IP

    The bridge forwards that packet. The gateway 172.17.0.1 is docker0.

    $ docker exec b ping -c 1 172.17.0.2
    64 bytes from 172.17.0.2: seq=0 ttl=64 time=0.1 ms
    $ docker exec b apk add --no-cache iproute2
    $ docker exec b ip route
    default via 172.17.0.1 dev eth0
  3. Step 3 · The name does not resolve
    $ docker exec b ping -c 1 a
    ping: bad address 'a'
    $ docker stop a b
Common mistakeUsing the legacy --link flag to get names on the default bridge. It is deprecated and writes a static /etc/hosts line that goes stale. Create a user-defined network instead.

Recap

Quick check

Container A pings B by IP on the default bridge. What forwards the frame?

Show answer

Answer: docker0, by MAC address.

docker0 is a layer-2 switch: it forwards from vethA to vethB by MAC address.

Why does ping a fail on the default bridge while ping 172.17.0.2 works?

Show answer

Answer: The container’s resolver is the host’s DNS, which has never heard of a.

No packet is sent: the name lookup fails first. Only user-defined networks get Docker DNS at 127.0.0.11.