Skip to content

Lesson 14 of 19 · 20m

docker0 Has No DNS: Bridge Networks, the Embedded Resolver, and East-West Isolation

docker0 carries traffic but no names; user-defined networks add the 127.0.0.11 resolver, aliases, and iptables-enforced isolation between networks.

-p 80:80 gets all the attention — the lesson on published ports covered how NAT chains route around your host firewall. But inbound traffic is only half the network story. The other half is east-west: how containers find each other, who can talk to whom, and why docker0, the default bridge, is a different tool than it looks.

docker0 is a wire, not a directory

Every container lands on docker0 — the default bridge, subnet 172.17.0.0/16 — unless you say otherwise. Containers on it can reach each other, by IP only. There is no name resolution: ping db fails because nothing knows db. The ancient fix was --link, which wrote the peer's IP into /etc/hosts and leaked environment variables into your container; it has been deprecated for years and should be treated as dead. The other legacy knob, --icc=false, disables inter-container communication — but only on the default bridge. It does nothing for user-defined networks.

Create a network and the shape changes:

docker network create app-tier
docker run --network app-tier --name db postgres:16
docker run --network app-tier --name api my-api

Now api resolves db. The mechanism: Docker runs an embedded DNS resolver inside every container on a user-defined network, listening at 127.0.0.11:53 — check /etc/resolv.conf inside one. Container names resolve. So do network-alias entries, so do Compose service names (Compose v2 auto-creates <project>_default and aliases each service by name). A scaled service returns all replica IPs — the embedded resolver does DNS round-robin for you.

Scoped aliases are the subtle part: an alias resolves only on the network where it was defined. A container on two networks presents different names to each — which is a segmentation primitive, not a curiosity.

Isolation is iptables, not politeness

Two containers on different user-defined networks cannot talk. Not by name — the resolver refuses — and not by IP, because Docker programs iptables to drop cross-network traffic. This is the actual network control Docker gives you: not authentication, not TLS, just packet-level segmentation. Use it. A frontend network for the proxy and a backend network for the database, with the app straddling both, is a real boundary. Everything on the same network can reach everything else on it — flat, unfiltered, no firewall inside the bridge.

The traps that already happened

  • Loopback resolvers get filtered. Docker copies the host's resolv.conf into containers but strips localhost nameservers — 127.0.0.53 (systemd-resolved's stub) and 127.0.0.1 (dnsmasq) are unreachable from inside a container. The silent fallback is public DNS — 8.8.8.8 — unless dns: in daemon.json or Compose says otherwise. Internal resolvers leak past this filter constantly.
  • MTU mismatch. docker0 defaults to 1500 bytes. Cloud VPCs hand you less — GCP's VPC MTU is 1460, several overlay networks sit at 1450. Oversized packets hang TLS handshakes and look like "containers can't reach the internet." Set it with "mtu" in daemon.json for docker0, or driver_options: {com.docker.network.driver.mtu: '1460'} on a Compose network.
  • Hairpin needs the proxy. A container reaching its own host's published port via the external IP works only because docker's userland proxy (docker-proxy, one process per published port) loops it back. "userland-proxy": false removes the helper — and hairpin NAT breaks with it.
  • --network host is not "faster bridge." It removes the network namespace entirely: the app binds real host ports, -p mappings become meaningless, localhost is the host's localhost, and — as CVE-2020-15257 showed — abstract Unix sockets like the containerd shim become reachable. The throughput gain is real for high-pps daemons; so is the lost boundary.
  • --add-host writes /etc/hosts entries at container start — the surgical fix when DNS is the wrong tool.

Try this

docker network create t && docker run -d --network t --name a nginx:alpine && docker run --rm --network t alpine sh -c 'cat /etc/resolv.conf; ping -c1 a' — watch 127.0.0.11 in resolv.conf and the ping succeed by name. Then docker run --rm alpine ping -c1 a on docker0 and watch it fail.

Field notes

  • docker network inspect app-tier lists attached containers and their IPs; docker inspect -f '{{json .NetworkSettings.Networks}}' shows which networks a container straddles.
  • Compose network names get a <project>_ prefix; --project-name pins it so aliases stay stable across environments.
  • IPv6 on bridges requires "ipv6": true and fixed-cidr-v6 in daemon.json — dual-stack is opt-in.
  • macvlan/ipvlan drivers give containers real IPs on your LAN; overlay networks are Swarm's job and out of scope for a single host.
  • localhost inside a container is the container. It resolves to the container's own loopback — the single most common first-day confusion, worth stating flatly.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.