DOCKER · Learning guideTheory · Labs · Knowledge checks
Chapter 06

Docker Compose and multi-service applications

Microservices and N-tier architecture

A multi-tier application can have a web frontend, an API and a database. Compose describes services, networks and volumes in one YAML file.

services:
  web:
    image: nginx:alpine
    ports:
      - "8080:80"
  worker:
    image: busybox
    command: ["sh", "-c", "sleep 3600"]
Hands-on lab: Save the example as compose.yaml.

Compose lifecycle

Modern Docker uses the docker compose subcommand. Compose can create, start, view logs and remove a multi-service stack.

docker compose config
docker compose up -d
docker compose ps
docker compose logs
docker compose down
Hands-on lab: Run the stack, view its services, then clean up.
Quick check: Does docker compose down remove named volumes by default?
Show answer
No. The -v flag also removes Compose-managed named volumes.

Configuration hygiene

Use environment variables for non-secret configuration. For secrets, prefer an appropriate secrets mechanism. Do not commit credentials or production .env files to Git.

docker compose down --remove-orphans
Hands-on lab: Discuss how to version-control a Compose project safely.