Docker DNS
Docker DNS is the embedded DNS server at 127.0.0.11 that containers on user-defined networks use to resolve container names, service names, and network aliases to current IP addresses.
How it works
Container IPs change on restart, so Docker keeps a name-to-IP map per network and answers lookups from inside each container. Containers on user-defined networks, including every Compose project network, get nameserver 127.0.0.11 in /etc/resolv.conf. Names that Docker does not know are forwarded to the host's configured upstream resolvers.
Try it
docker network create payment-networkdocker run -d --name db --network payment-network -e POSTGRES_PASSWORD=devpassword postgres:16docker run -d --name api --network payment-network alpine sleep 3600docker exec api cat /etc/resolv.conf # nameserver 127.0.0.11docker exec api nslookup dbNetwork aliases
docker run -d --name postgres-primary --network payment-network \ --network-alias db --network-alias database postgres:16Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
| Name will not resolve | Default bridge network | Use a user-defined network |
| Cannot resolve across apps | Different networks | docker network connect |
| Stale IP | App cached the lookup | Restart client or fix its DNS cache |
| Compose name fails | Different project network | Share a network between projects |
RememberThe default bridge network has no name resolution. Use a user-defined network or Compose.
Common MistakeHardcoding container IPs in config. Always use names.
Frequently Asked Questions
Why can't containers resolve each other by name on the default bridge?
Docker enables its embedded DNS only on user-defined networks. The default bridge keeps legacy behavior with IP access or the deprecated --link flag, which is why custom networks are recommended.
Can a container resolve names on a network it is not connected to?
No. Resolution is scoped to networks the container is attached to, so connect it to each network whose members it must reach by name.
Does Docker DNS handle external domains?
Yes. Queries for names Docker does not manage are forwarded to the upstream DNS servers from the host or daemon configuration.