>_ IzzyLab

Hands-on task

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

docker compose: project networks

medium~15 min

/root/shop holds the compose project shop of three services on izzylab/minihttp:1: web → api → db. It's running, but all three services sit in the project's one default network, and the storefront can't be opened from the server.

Rewrite /root/shop/compose.yaml and bring the project up again (docker compose in /root/shop):

  • two project networks: front and back;
  • web only in front, db only in back, api in both;
  • web is published on the server's 127.0.0.1:8080 (the service's port is 8080);
  • services call each other by service name, and db can't be reached from web.

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 compose
  • compose networks
  • ports

Topic breakdown

Compose creates a <project>_default network for every project and connects all services to it: they find each other by service name through Docker's built-in DNS. Convenient, but flat — everyone sees everyone. Your own networks are declared in the top-level networks: and listed under the services: then a service is connected only to the ones named, and no default network is created for it. The project name defaults to the directory name, so networks get names like shop_front. docker compose up -d compares the file with the running containers and recreates only the services that changed; ports: works just like -p, including binding to an address.

What's checked

  1. The shop project is up: web, api and db are running
  2. web only in front, db only in back, api in both
  3. web is published only on 127.0.0.1:8080
  4. From the server, 127.0.0.1:8080/call: web reaches api
  5. api reaches db
  6. db can't be reached from web

What it looks like