Interview's MateDocker
Interview's Mate

Docker

Compose · Networking · Security · Ops

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Docker topics
Lesson 64/ 160
04. Docker Networking

Built-in Docker DNS & Automatic Service Discovery by Container Name

Resolve containers by name on user-defined networks without hard-coded IPs.

BeginnerEmbedded DNS · Name Resolution3 quiz questions
Practice DevOps Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

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}} db for 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

Loading interactive 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.

Concrete Embedded DNS setup

docker run --rm --network shop nicolaka/netshoot:latest dig +short db shop; docker inspect -f {{json .Config.Dns}} db

Key takeaway: Prove Name Resolution with 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.

Deliberate failure test

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.

Key takeaway: Embedded DNS is lightweight and dynamic; external service meshes add health-aware discovery and policy when simple name resolution is not enough.

How it works, step by step

Step 1 of 4
Design

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

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.
Key numbers at this step
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 IPAddress in 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

Explicit Embedded DNS
Best for: Resolve containers by name on user-defined networks without hard-coded IPs, with a reviewed runbook.

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.

Ambient default
Best for: Short-lived Name Resolution experiments with low blast radius.

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.

Managed Discovery
Best for: Teams that centralize Discovery policy across many workloads.

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}} db as proof and skipping run 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}} db address 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?
Interview tip: Give one concrete operation-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

Loading quiz

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.

Open DevOps Q&A →Tech Learn Q&A
Previous topic
Default Bridge vs User-Defined Bridge Networks
Next topic
Creating, Inspecting & Connecting Custom Networks (docker network)