Opscraft
Docker · Lesson 7 of 11 · 4 min read

Networking internals

Bridge networking, step by step

When Docker starts it creates a Linux bridge, docker0 (172.17.0.1/16 by default). For each container on the default bridge:

  1. A new network namespace is created.
  2. A veth pair is created — one end inside the container as eth0, the other attached to docker0 on the host.
  3. The container gets an IP from the bridge subnet and a default route via docker0.
  4. Outbound traffic is SNAT/MASQUERADEd by iptables to the host's IP.
  5. -p 8080:80 adds a DNAT rule: traffic to host:8080 → container:80 (plus docker-proxy for some cases).
ip link show master docker0          # veth interfaces on the bridge
iptables -t nat -L DOCKER -n         # DNAT rules for published ports
docker network inspect bridge

-p 8080:80 binds on all host interfaces (0.0.0.0). -p 127.0.0.1:8080:80 limits it to localhost. Note that Docker's iptables rules can bypass host firewalls like ufw — published ports may be reachable even if ufw "blocks" them.

Enlarge diagramHOST 10.0.1.20webeth0 172.17.0.2apieth0 172.17.0.3docker0 bridge172.17.0.1iptablesMASQUERADE out ·DNAT 8080 → web:80eth0 (host NIC)to the networkvethveth
Figure 1. Default bridge networking: each container gets a veth pair onto docker0. Outbound traffic is NATed to the host IP; -p adds a DNAT rule for inbound.
Swipe sideways to see all of it, or tap to open it full screen.

Network drivers

Driver What it does Use
bridge (default) Private network on one host with NAT Default single-host use
User-defined bridge Same, plus automatic DNS by container name and better isolation Always prefer over the default bridge
host No network namespace; shares the host's stack Max performance, no port mapping; port clashes possible
none Loopback only Isolated batch jobs
overlay VXLAN network spanning hosts Swarm services, multi-host
macvlan / ipvlan Container gets an address on the physical network Legacy apps needing L2 presence

DNS between containers

On a user-defined network, Docker's embedded DNS server at 127.0.0.11 resolves container names and network aliases:

docker network create appnet
docker run -d --name db --network appnet postgres:16
docker run -d --name api --network appnet -e DB_HOST=db myapi

On the default bridge, containers can't resolve each other by name (the legacy --link flag is deprecated).

Containers inherit DNS settings from the host's /etc/resolv.conf (filtered to remove localhost resolvers). If a container can't resolve names but the host can, check the container's /etc/resolv.conf, the daemon's "dns" setting in daemon.json, and corporate DNS/VPN on the host.

Enlarge diagramNETWORK: APPNETapiDB_HOST=dbDNS127.0.0.11db172.18.0.3On the default bridge, names donot resolve: create a network."db"?
Figure 2. On a user-defined network, Docker's built-in DNS at 127.0.0.11 resolves container names. On the default bridge it does not.
Swipe sideways to see all of it, or tap to open it full screen.

Subnet clashes

Docker's default pools (172.17.0.0/16 onwards) can overlap with corporate or VPC ranges, breaking routes to those networks from the host. Fix with "bip" and "default-address-pools" in daemon.json.