Skip to main content

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.

sequenceDiagram participant A as api container participant D as Docker DNS 127.0.0.11 participant B as postgres container A->>D: resolve postgres D-->>A: 172.18.0.3 Note over B: postgres restarts with a new IP A->>D: resolve postgres D-->>A: 172.18.0.4

Try it

Bash
docker network create payment-network
docker run -d --name db --network payment-network -e POSTGRES_PASSWORD=devpassword postgres:16
docker run -d --name api --network payment-network alpine sleep 3600
docker exec api cat /etc/resolv.conf # nameserver 127.0.0.11
docker exec api nslookup db

Network aliases

Bash
docker run -d --name postgres-primary --network payment-network \
--network-alias db --network-alias database postgres:16

Troubleshooting

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
Remember

The default bridge network has no name resolution. Use a user-defined network or Compose.

Common Mistake

Hardcoding 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.

Found a mistake, an outdated step or a broken link?