>_ IzzyLab

Hands-on task

This task is step 2 of the course “Docker networking”

DNS in Docker: name, alias and resolver

easy~12 min

The app network runs the database db-v2 and the reporting service report. In report's settings the database is written as db (UPSTREAM=db:8080), and since the move to db-v2 reports are broken: report's /call answers 502.

Make the name db in the app network lead to the db-v2 container. Don't recreate or rename either container: report has a queue building up, and other services expect db-v2 under that name.

While you're at it, find out which DNS server the report container queries and write its address (IP only) to /root/resolver.txt.

The lab has its own Docker with no internet access; the images are already loaded: izzylab/minihttp:1, alpine:3.21, busybox:1.36, nginx:1.27-alpine. izzylab/minihttp is a tiny HTTP service on port 8080: GET / answers <NAME> ok, GET /call itself goes to http://<UPSTREAM>/ and answers <NAME> -> <the neighbor's reply> (or 502), GET /env shows its settings. It is configured with the environment variables NAME, PORT, BIND (the address it listens on) and UPSTREAM.

What you'll practise:
  • docker dns
  • network alias
  • resolv.conf

Topic breakdown

In a user-defined Docker network every container's /etc/resolv.conf lists a single DNS server: Docker's built-in resolver, listening on a loopback address inside the container's network namespace (which one exactly is visible in the container's /etc/resolv.conf). It answers for the names of the containers in that network and their aliases, and forwards everything else to the host's DNS servers. An alias (--network-alias on docker run, --alias on docker network connect) is an extra name for a container that works in one network only: that way one database can be called db in the application's network and have no name at all in the next one. If several containers answer to the same name, DNS returns all their addresses — a simple way to balance load. Aliases are stored in the network connection's settings, so you change them by reconnecting, without restarting the container.

What's checked

  1. db-v2 and report are running, not recreated or renamed
  2. In the app network the name db leads to db-v2
  3. Reports reach the database again (report's /call)
  4. /root/resolver.txt holds the address of the DNS server report queries

What it looks like