✦ For everyone, free.

Practical knowledge for real and everyday life

Home

7.3.2.5 External DNS Config

A focused guide to External DNS Config, connecting core concepts with practical Docker and container operations.

External DNS config addresses how a container resolves hostnames outside of Docker's own embedded DNS for container names — typically inheriting the host's DNS configuration by default, with the ability to explicitly override it for specific needs.

Default Behavior: Inheriting the Host's DNS Settings

Without explicit configuration, a container typically uses the same external DNS servers the host itself is configured to use.

docker run --rm alpine cat /etc/resolv.conf

This usually reflects DNS server addresses derived from the host's own configuration.

Overriding DNS Servers Explicitly

A container can be given specific DNS servers to use, overriding whatever it would otherwise inherit from the host.

docker run -d --dns=8.8.8.8 --dns=8.8.4.4 myapp:1.0

This might be useful for testing against a specific DNS provider, or in environments where the host's own DNS configuration isn't appropriate for the container's needs.

Configuring DNS at the Daemon Level

DNS servers can also be configured daemon-wide, applying as the default for every container started on that host unless individually overridden.

{
  "dns": ["8.8.8.8", "8.8.4.4"]
}

This daemon configuration file (typically /etc/docker/daemon.json) sets a default applied broadly, rather than needing to be specified for every individual container.

Diagnosing External DNS Resolution Issues

When a container can resolve internal container names correctly but fails to resolve external hostnames, the container's external DNS configuration specifically is a likely place to investigate.

docker exec myapp nslookup example.com
docker exec myapp cat /etc/resolv.conf
Why External DNS Config Matters

Understanding that external hostname resolution is governed by separate configuration from Docker's own internal container-name resolution helps correctly diagnose issues where one type of resolution (internal or external) works while the other doesn't, since they depend on entirely different underlying mechanisms.