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
A packet from A to B
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.
-
b checks its own
/etc/hosts. Docker writes only b itself and localhost there. There is no line fora.$ docker exec b cat /etc/hosts 127.0.0.1 localhost 172.17.0.3 3f1c2a9b7d10 # b only, no a -
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 calleda.$ docker exec b cat /etc/resolv.conf nameserver 192.168.1.1 # the host's DNSThe 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.
-
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, sodocker0never 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 bridge | User-defined bridge | |
|---|---|---|
nameserver in resolv.conf | the host's DNS | 127.0.0.11 (Docker DNS) |
ping a | bad address 'a' | works |
| a restarts with a new IP | hard-coded IPs break | the 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 this | It shows |
|---|---|
ip addr show docker0 | the bridge and its IP (172.17.0.1) |
ip link | one vethXXXX per running container |
docker inspect -f '{{.NetworkSettings.IPAddress}}' a | the container's address on the bridge |
docker exec b ip route | default via 172.17.0.1: the gateway is docker0 |
Try it yourself
-
Step 1 · Two containers on the default bridge
Leaving off
--networkattaches them tobridge(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 -
Step 2 · Ping the IP
The bridge forwards that packet. The gateway
172.17.0.1isdocker0.$ 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 -
Step 3 · The name does not resolve
$ docker exec b ping -c 1 a ping: bad address 'a' $ docker stop a b
--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
docker0is a virtual switch; every container on the default bridge shares its subnet.- A veth pair is a virtual cable: one end is the container
eth0, the other plugs into the bridge. - The bridge forwards by MAC address, so container-to-container traffic never leaves the host.
- The default bridge has no DNS, so containers can only find each other by IP.
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.