Skip to content
BotServBotServ
DockerDNSNetworkContainer namesAliases

Internal DNS Names in Docker

Docker DNS and internal name resolution. Container names, custom networks, aliases and DNS troubleshooting.

S

schutzgeist

3 min read
Internal DNS Names in Docker

Internal DNS Names in Docker

What this article covers

  • How containers reach each other by name.
  • DNS in custom networks.
  • Aliases and network names.
  • Troubleshooting DNS issues.
  • Relationship to /etc/hosts.

Introduction: Internal DNS Names in Docker

Docker provides built-in DNS resolution within custom networks. Containers can communicate not only by IP address, but also by service name, alias, or container name. This makes Compose setups significantly more stable, since IP addresses can change but names remain consistent. Understanding how Docker’s internal DNS works lets you run applications without hardcoded IPs.

This article shows how Docker’s internal DNS functions and how to use it effectively.

Key Terms

  • Container name: The name of the container in the Docker system.
  • Service name: The name defined in Compose.
  • Alias: An additional DNS name.
  • Custom network: A network with built-in DNS resolution.
  • Default bridge: The standard network without DNS.
  • DNS resolver: The service that resolves names to IP addresses.
  • Hostname: The name the container itself carries.

Why Custom Networks?

In the default bridge, containers must communicate via IP address. Custom networks bring built-in DNS:

docker network create mein-netz
docker run -d --name web --network mein-netz nginx
docker run -d --name app --network mein-netz curlimages/curl curl http://web

web resolves automatically to its IP address.

In Compose

services:
  web:
    image: nginx
  app:
    image: curlimages/curl
    command: curl http://web

Compose automatically creates a network where web is available as a DNS name.

Aliases

services:
  db:
    image: postgres
    networks:
      backend:
        aliases:
          - datenbank
          - db-primary

networks:
  backend:

Other containers can reach db, datenbank, or db-primary.

Setting a Hostname

services:
  app:
    image: mein-app
    hostname: app-1

Inside the container, app-1 becomes its own hostname.

Checking DNS

Inside a container:

nslookup web
nslookup db

If nslookup is not available:

getent hosts web

DNS Server

Docker uses an internal resolver. External DNS servers can be set in Compose:

services:
  app:
    image: mein-app
    dns:
      - 1.1.1.1
      - 8.8.8.8

This overrides the container’s DNS only for external lookups.

Multiple Networks

A container can belong to several networks and will have multiple names:

services:
  app:
    networks:
      - frontend
      - backend

networks:
  frontend:
  backend:

Other containers in the same network reach app via its service name.

DNS Troubleshooting

Names not resolving

  • Are containers in the same network?
  • Check the spelling of the service name.
  • Did you restart Compose?

IP has changed

This is normal. The container name stays stable, but the IP may not.

External names not reachable

  • Verify Docker’s DNS forwarding is working.
  • Set the dns option in Compose.
  • Check firewall rules.

Names with hyphens

Docker DNS supports hyphens. Dots should be avoided.

Tips

  • Always use custom networks or Compose.
  • Choose clear, unambiguous service names.
  • Use aliases for backward compatibility.
  • Don’t hardcode IPs in URLs.
  • Test DNS inside the container when issues occur.
  • Configure external DNS separately.

Further Reading and Resources

FAQ: Internal Docker DNS

Can containers reach each other by name in the default bridge network? No, there is no built-in DNS there.

What is the DNS name in Compose? The service name from the services: section.

What are aliases? Additional names for the same container within a network.

Why does the IP change? Containers can receive new IPs when they restart.

Can I set a custom DNS server? Yes, via the dns option in Compose or with docker run.

Sources and Further Reading

Summary: Internal DNS Names in Docker

Custom Docker networks provide internal DNS resolution that makes containers reachable by name. Compose uses this automatically, aliases enable additional names, and hostname configuration sets the container’s internal machine name. Skipping clear names and hardcoding IPs creates fragile setups. With Docker DNS, connections remain stable even when IP addresses change.

Back to Blog
Share:

Related Posts