📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials Docker Docker Compose

Docker Compose

6 min read Quiz at the end
Define multi-container apps in YAML with services, volumes, env vars, and healthchecks.

Docker Compose

# docker-compose.yml
services:
  web:
    build: .
    ports:
      - "3000:3000"
    environment:
      DATABASE_URL: postgresql://user:pass@db:5432/mydb
    depends_on:
      db:
        condition: service_healthy

  db:
    image: postgres:16
    environment:
      POSTGRES_PASSWORD: pass
      POSTGRES_USER: user
    volumes:
      - pgdata:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD", "pg_isready", "-U", "user"]
      interval: 5s
      retries: 5

volumes:
  pgdata:

# Commands
docker compose up -d
docker compose down
docker compose logs -f
docker compose exec web bash
Topic Quiz · 3 questions

Test your understanding before moving on

1. What does docker compose up -d do?
💡 docker compose up -d starts all defined services in the background.
2. What does depends_on with service_healthy ensure?
💡 condition: service_healthy makes the dependent service wait for the healthcheck to pass.
3. How do you view logs from all Compose services?
💡 docker compose logs -f streams logs from all services defined in the Compose file.