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-apiNow 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.confinto containers but strips localhost nameservers —127.0.0.53(systemd-resolved's stub) and127.0.0.1(dnsmasq) are unreachable from inside a container. The silent fallback is public DNS —8.8.8.8— unlessdns:in daemon.json or Compose says otherwise. Internal resolvers leak past this filter constantly. - MTU mismatch.
docker0defaults 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 fordocker0, ordriver_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": falseremoves the helper — and hairpin NAT breaks with it. --network hostis not "faster bridge." It removes the network namespace entirely: the app binds real host ports,-pmappings 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-hostwrites/etc/hostsentries 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-tierlists 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-namepins it so aliases stay stable across environments. - IPv6 on bridges requires
"ipv6": trueandfixed-cidr-v6in daemon.json — dual-stack is opt-in. macvlan/ipvlandrivers give containers real IPs on your LAN; overlay networks are Swarm's job and out of scope for a single host.localhostinside 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?
Keep reading
Related articles from the SudoSecurity blog.
PostgreSQL 19 Is Out. REPACK Kept My Writes Running. The Docker Upgrade Will Stop Your App.
PostgreSQL 19 shipped on November 19 with REPACK (CONCURRENTLY), which removes table bloat without blocking writes. I measured it against VACUUM FULL, ran the upgrade from 18, and checked what breaks for self-hosters: Docker tags that refuse to start, a config setting that stops the server, and...
Self-Hosting Prometheus and Grafana: Infrastructure Monitoring That Actually Works
Build a production-grade monitoring stack with Prometheus and Grafana from scratch. Covers architecture, Docker Compose deployment, Node Exporter, alerting with Alertmanager, PromQL from basics to advanced, pre-built dashboards, and everything SudoSecurity uses to monitor its own infrastructure.
What is Kubernetes? Container Orchestration at Scale
Kubernetes runs your Docker containers across a cluster of machines, handles scheduling, health checking, rolling deployments, auto-scaling, and self-healing. When your application outgrows a single server, Kubernetes is how it runs on ten.
What is Docker? Containers, Images, and Why Every Developer Needs to Know This
Docker packages your application and everything it needs to run into a container that behaves identically on your laptop, your teammate's machine, and the production server. "It works on my machine" stops being a problem. Here is how it actually works and what production usage looks like.