Built-in Docker DNS & Automatic Service Discovery by Container Name
Resolve containers by name on user-defined networks without hard-coded IPs.
In plain words
Resolve stable service names only across networks both containers join, and use the resolver address as an observation point rather than hard-coding 127.0.0.11 into applications.
Think of it like…
The resolver is the building’s receptionist: it knows which rooms currently exist on a specific floor and asks the city directory for outside addresses.
Where you’ve seen it
In practice, docker run --rm --network shop nicolaka/netshoot:latest dig +short db shop; docker inspect -f {{json .Config.Dns}} db is the concrete move for this job: resolve containers by name on user-defined networks without hard-coded IPs. The release is not accepted until run nslookup against the embedded resolver, reproduce after db recreation, and compare its new A record with docker inspect IPAddress confirms the result.
Words you’ll hear
- Embedded DNS
- The implementation control in
docker run --rm --network shop nicolaka/netshoot:latest dig +short db shop; docker inspect -f {{json .Config.Dns}} dbfor resolve containers by name on user-defined networks without hard-coded IPs. - Name Resolution
- The result to observe with
run nslookup against the embedded resolver, reproduce after db recreation, and compare its new A record with docker inspect IPAddress, rather than infer from a successful command alone. - Discovery
- The production boundary exposed when hard-coding the old container IP in connection strings, or changing /etc/resolv.conf inside a layer instead of using --dns.
Visual diagram
Theory & deep dive
Embedded DNS control path
The concrete mechanism is docker run --rm --network shop nicolaka/netshoot:latest dig +short db shop; docker inspect -f {{json .Config.Dns}} db. The observable result is run nslookup against the embedded resolver, reproduce after db recreation, and compare its new A record with docker inspect IPAddress; if those disagree, inspect the runtime evidence before changing unrelated settings.
Resolve containers by name on user-defined networks without hard-coded IPs. Keep Embedded DNS, Name Resolution and Discovery in the same deployment record so the intent and the observed state cannot drift apart.
docker run --rm --network shop nicolaka/netshoot:latest dig +short db shop; docker inspect -f {{json .Config.Dns}} db
run nslookup against the embedded resolver, reproduce after db recreation, and compare its new A record with docker inspect IPAddress, not with command success alone.Discovery failure boundary
DNS caching and application caches can make a restarted container appear unavailable even after Docker updates the record. NXDOMAIN means the network/name boundary is wrong; a timeout can instead point to upstream DNS, firewall or a tiny DNS search-domain mismatch. The narrow failure to design for is hard-coding the old container IP in connection strings, or changing /etc/resolv.conf inside a layer instead of using --dns.
Accept this compromise explicitly: Embedded DNS is lightweight and dynamic; external service meshes add health-aware discovery and policy when simple name resolution is not enough. The controlled check-run nslookup against the embedded resolver, reproduce after db recreation, and compare its new A record with docker inspect IPAddress-also identifies the point where a different design is safer.
Exercise this failure safely: hard-coding the old container IP in connection strings, or changing /etc/resolv.conf inside a layer instead of using --dns.
How it works, step by step
Step 1 of 41. State the boundary
Write down why the workload needs this: DNS caching and application caches can make a restarted container appear unavailable even after Docker updates the record. NXDOMAIN means the network/name boundary is wrong; a timeout can instead point to upstream DNS, firewall or a tiny DNS search-domain mismatch.
- Intent
- Embedded DNS
When to use it & trade-offs
What it is
Docker runs an embedded DNS resolver at 127.0.0.11 for containers on user-defined bridge and overlay networks. It answers container names, aliases and network-scoped records, and forwards external queries to configured upstream resolvers.
Why it matters: DNS caching and application caches can make a restarted container appear unavailable even after Docker updates the record. NXDOMAIN means the network/name boundary is wrong; a timeout can instead point to upstream DNS, firewall or a tiny DNS search-domain mismatch.
When to reach for it
- The fit is strongest for this job: resolve containers by name on user-defined networks without hard-coded IPs. Pair it with
run nslookup against the embedded resolver, reproduce after db recreation, and compare its new A record with docker inspect IPAddressin the runbook. - Production Embedded DNS changes should make Name Resolution observable through
docker run --rm --network shop nicolaka/netshoot:latest dig +short db shop; docker inspect -f {{json .Config.Dns}} db, rather than trusting the runtime default. - Keep a rollback example for the case where hard-coding the old container IP in connection strings, or changing /etc/resolv.conf inside a layer instead of using --dns.
When to avoid or be careful
- Do not accept command success while the system can still fail by hard-coding the old container IP in connection strings, or changing /etc/resolv.conf inside a layer instead of using --dns.
- Avoid erasing Discovery protection merely to dodge this cost: “Embedded DNS is lightweight and dynamic; external service meshes add health-aware discovery and policy when simple name resolution is not enough”.
- Do not replace the evidence path-
run nslookup against the embedded resolver, reproduce after db recreation, and compare its new A record with docker inspect IPAddress-with a screenshot or a mutable tag.
docker run --rm --network shop nicolaka/netshoot:latest dig +short db shop; docker inspect -f {{json .Config.Dns}} db: practical choices
Strengths: Docker runs an embedded DNS resolver at 127.0.0.11 for containers on user-defined bridge and overlay networks. It answers container names, aliases and network-scoped records, and forwards external queries to configured upstream resolvers.
Watch out: Embedded DNS is lightweight and dynamic; external service meshes add health-aware discovery and policy when simple name resolution is not enough.
Strengths: It can begin with docker run --rm --network shop nicolaka/netshoot:latest dig +short db shop; docker inspect -f {{json .Config.Dns}} db and fewer surrounding controls.
Watch out: It silently accepts hard-coding the old container IP in connection strings, or changing /etc/resolv.conf inside a layer instead of using --dns, which makes the result hard to reproduce after promotion.
Strengths: DNS caching and application caches can make a restarted container appear unavailable even after Docker updates the record. NXDOMAIN means the network/name boundary is wrong; a timeout can instead point to upstream DNS, firewall or a tiny DNS search-domain mismatch.
Watch out: The platform adds an ownership and debugging layer; retain run nslookup against the embedded resolver, reproduce after db recreation, and compare its new A record with docker inspect IPAddress as the direct check.
Interview signals & numbers to know
When this topic comes up
- docker run --rm --network shop nicolaka/netshoot:latest dig +short db shop; docker inspect -f {{json .Config.Dns}} db
- run nslookup against the embedded resolver, reproduce after db recreation, and compare its new A record with docker inspect IPAddress
- Failure signature: hard-coding the old container IP in connection strings, or changing /etc/resolv.conf inside a layer instead of using --dns
- Trade-off: Embedded DNS is lightweight and dynamic; external service meshes add health-aware discovery and policy when simple name resolution is not enough.
Benchmarks & rules of thumb
- 127.0.0.11
- common embedded Docker DNS endpoint
- 53/udp and tcp
- DNS query transports
- TTL 600
- possible consumer cache value; applications should not promise one fixed duration
Common mistakes & follow-ups
Common interview mistakes
- Treating a successful
docker run --rm --network shop nicolaka/netshoot:latest dig +short db shop; docker inspect -f {{json .Config.Dns}} dbas proof and skippingrun nslookup against the embedded resolver, reproduce after db recreation, and compare its new A record with docker inspect IPAddress. - Hard-coding the old container IP in connection strings, or changing /etc/resolv.conf inside a layer instead of using --dns
- Optimizing Embedded DNS without accepting that embedded DNS is lightweight and dynamic; external service meshes add health-aware discovery and policy when simple name resolution is not enough.
Likely interviewer follow-ups
- Why does
docker run --rm --network shop nicolaka/netshoot:latest dig +short db shop; docker inspect -f {{json .Config.Dns}} dbaddress Embedded DNS here rather than through application code? - How would you distinguish healthy Name Resolution from the failure “hard-coding the old container IP in connection strings, or changing /etc/resolv.conf inside a layer instead of using --dns” using
run nslookup against the embedded resolver, reproduce after db recreation, and compare its new A record with docker inspect IPAddress? - When would this trade-off-“Embedded DNS is lightweight and dynamic; external service meshes add health-aware discovery and policy when simple name resolution is not enough”-justify a different Discovery design?
docker run --rm --network shop nicolaka/netshoot:latest dig +short db shop; docker inspect -f {{json .Config.Dns}} db-and one proof-run nslookup against the embedded resolver, reproduce after db recreation, and compare its new A record with docker inspect IPAddress. Then name the boundary: hard-coding the old container IP in connection strings, or changing /etc/resolv.conf inside a layer instead of using --dns.Knowledge check
Put it into practice
Practice related interview Q&A
Apply Built-in Docker DNS & Automatic Service Discovery by Container Name with generative AI interview Q&A and hands-on practice.