Skip to content

Lesson 5 of 9 · 24m

DNS, Service Discovery, and Egress Control

Understand Docker DNS behavior, split-horizon failure modes, outbound identity, and practical egress restriction patterns.

Container DNS feels effortless until traffic splits across resolvers, a compose project changes names, or an egress rule works in staging but not on the hardened host. DNS is not a small convenience layer. It decides which identity your workload asks for, which address it receives, and often which trust boundary it crosses next.

Docker's embedded resolver is a control point

Containers on user-defined networks commonly use Docker's embedded DNS at 127.0.0.11 inside the container:

docker network create appnet
docker run -d --name api --network appnet nginx:1.27
docker run --rm --network appnet alpine:3.20 sh -c   'cat /etc/resolv.conf; getent hosts api'

The embedded resolver answers service and container names, then forwards other queries upstream according to host and daemon configuration. That means resolution behavior can differ between the default bridge, user-defined bridges, compose projects, Kubernetes, and host networking.

Names are scoped, not global truth

Compose prefixes, network aliases, and service names are scoped by project and network. Two containers named api can coexist on different networks and resolve differently for different clients. If an application needs a canonical service identity, do not infer it only from a local container name. Configure explicit service discovery or environment-driven endpoints.

services:
  web:
    image: nginx:1.27
    networks:
      edge:
        aliases:
          - public-web
  api:
    image: ghcr.io/example/api:2.4.1
    networks:
      edge:
      backend:

Here api is reachable from both networks, while db might intentionally exist only on backend. Network attachment is part of the access-control design.

Egress is an identity problem

Outbound restrictions often begin as "allow only the package registry" and end as a mess because containers all share the host's NAT identity. Before writing firewall policy, classify outbound flows:

registry pulls          image supply chain and deployment path
package mirrors         build-time dependency retrieval
application APIs        business dependencies
telemetry/licensing     vendor-specific operational traffic
metadata endpoints      cloud control-plane credential exposure risk

DNS destination names are poor enforcement keys for high-value egress controls because IPs change and one CDN address can host thousands of names. Prefer proxy egress, explicit allowlists at a controlled egress point, or workload identity integrated with the platform.

Block the metadata path intentionally

On cloud hosts, containers often inherit network access to link-local metadata services such as 169.254.169.254. If cloud credentials are available there, an application vulnerability becomes instance identity theft. Test from inside the container, not merely from the host:

docker run --rm curlimages/curl:8.10.1   --connect-timeout 2 -sS http://169.254.169.254/latest/meta-data/ || true

The correct control depends on your cloud and runtime: host firewall rules, metadata service hardening, workload identity, or network policy. The wrong control is assuming containers cannot reach what the host can reach.

IPv6 and split DNS change the map

A service may resolve over IPv6 while your egress policy only understands IPv4. Internal zones may resolve differently inside the cluster, on the host, and from a developer laptop. Record the resolver, query type, answer family, and client network when debugging. dig without context produces confident nonsense.

Field notes

  • Alpine images historically used musl resolver behavior that differs from glibc in edge cases; do not extrapolate one distro's DNS behavior to every image.
  • Hard-coded upstream DNS servers break in hotels, corporate networks, IPv6-only networks, and split-horizon deployments.
  • network_mode: host bypasses Docker embedded DNS service names.
  • Blocking outbound 443 at the host does not distinguish image pulls, application traffic, and telemetry if they share NAT.
  • A proxy with explicit credentials often provides better auditability than hundreds of brittle IP rules.

Was this lesson helpful?

Sign in to rate