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:
- A new network namespace is created.
- A veth pair is created — one end inside the container as
eth0, the other attached todocker0on the host. - The container gets an IP from the bridge subnet and a default route via
docker0. - Outbound traffic is SNAT/MASQUERADEd by iptables to the host's IP.
-p 8080:80adds a DNAT rule: traffic to host:8080 → container:80 (plusdocker-proxyfor 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.
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.
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.