>_ IzzyLab

Hands-on task

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

Containers can't find each other by name

easy~8 min

Two containers from izzylab/minihttp:1 run in Docker's default network: api and web, which has UPSTREAM=api:8080. But web can't reach api: docker exec web wget -qO- http://127.0.0.1:8080/call returns an error, and docker exec web wget -qO- http://api:8080/ says the address can't be resolved.

Create your own network shop (driver bridge) and connect both containers to it so that web finds api by name. You don't have to recreate the containers.

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 network
  • bridge
  • docker dns

Topic breakdown

Right after installation Docker creates the bridge network (the docker0 bridge on the host), and a container started without --network lands there. Addresses are handed out and containers see each other by IP, but there are no names: Docker's built-in DNS works only in user-defined networks, the ones made with docker network create. In such a network a container finds a neighbor by its container name, and the name lives exactly as long as the container is connected to the network. You can add a network to a running container (docker network connect) and remove it (docker network disconnect): the container gets or loses one more interface, and the process inside isn't restarted. Hence the first rule: every application gets its own network, and the default bridge is only for standalone containers.

What's checked

  1. There is a user-defined network shop with the bridge driver
  2. web and api are connected to shop
  3. From web, the name api reaches the api service
  4. web reaches api through its UPSTREAM (/call)

What it looks like