Docker container DNS: connect by name
Lab prerequisites
Use an approved, disposable Linux Docker Engine VM with no external network access, ordinary bridge/NAT settings, and Engine 28.0.0 or later for publication labs. Verify the local context, server version, and that all bm-v05 names used in this example are unused. Use a reviewed, preloaded busybox:1.37 image; record its digest and check that httpd, wget and nslookup are present where used. The tag is not immutable. Run commands individually, stop on unexpected failure, and clean up only resources you created. Results below are expected, not observed. Before contacting the Engine, verify the effective local endpoint including DOCKER_HOST, DOCKER_CONTEXT and CLI overrides. Recheck the approved local image ID and native platform; if the recorded digest is unavailable, report it as unknown rather than inventing one. Use owner-set resource and time limits. If prerequisites cannot be confirmed, do the paper exercise instead. The VM must have no other untrusted workloads, no external routes and no direct-routing exceptions. A loopback mapping or internal bridge alone does not provide these guarantees. Use only a patched, supported Engine release meeting the stated minimum.
Names instead of changing addresses
Docker provides name resolution for peers on a user-defined bridge. A client can use the server container name in its URL. The default bridge does not provide the same automatic name-based discovery. Container addresses can change after recreation, so names make the configuration easier to maintain. Name resolution only locates an endpoint; it does not authenticate the service.
Create a server and request by name
Use a fresh internal bridge. The fixture HTTP server listens on container port 8080 and has no published host port. A short-lived client uses the same network. If the server is not ready, inspect its state and retry the client once manually.
docker network create --driver bridge --internal bm-v05-dns-netdocker run -d --pull=never --name bm-v05-dns --network bm-v05-dns-net busybox:1.37 sh -c 'mkdir -p /tmp/www && printf "ByteMind network lab\n" > /tmp/www/index.html && exec httpd -f -p 8080 -h /tmp/www'docker run --rm --pull=never --network bm-v05-dns-net busybox:1.37 wget -T 3 -qO- http://bm-v05-dns:8080/Expected response: ByteMind network lab. The name identifies the server and 8080 is its internal listening port. No host port is used.
Inspect name lookup separately
A DNS lookup is a different check from an HTTP request. The answer address can vary; successful lookup does not show whether a process is listening. Use nslookup only if the applet is available in the reviewed fixture. The embedded DNS resolver is available on user-defined networks; a lookup by name can succeed even when the HTTP process has stopped. Resolve only the synthetic lab name, and record the lookup and HTTP result separately.
docker run --rm --pull=never --network bm-v05-dns-net busybox:1.37 nslookup bm-v05-dnsdocker stop bm-v05-dnsdocker rm bm-v05-dnsdocker network rm bm-v05-dns-netExpected: a name lookup result for the server, followed by cleanup. DNS output format and address are not fixed.
Manual practice
Write the URL a peer would use for a container named catalog listening on 9000 on a common custom bridge. Explain why a host mapping is unnecessary.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Docker container DNS: connect by name — Knowledge check
Apply the concepts from this lesson.
A server named catalog listens on port 9000. What URL should a peer on its custom bridge use?
Why prefer the container name to a hard-coded IP?
A name resolves successfully. What is still unknown?