Table of Contents

Docker Compose

Compose defines multi-container applications in docker-compose.yml. Services are containers; each service uses an image and configuration. docker compose up starts all services; docker compose down stops and removes them. Compose creates a shared network so services reach each other by service name.

$ docker compose up                   # start all services
$ docker compose up -d                # start in background
$ docker compose down                 # stop and remove containers
$ docker compose logs -f              # stream logs from all services
$ docker compose ps                   # list running services
 
# docker-compose.yml
services:
  web:
    image: nginx:latest
    ports:
      - "8080:80"
  db:
    image: postgres:latest
    environment:
      POSTGRES_PASSWORD: secret

Compose automatically creates a network named <project>_default where all services can reach each other by their service name (e.g., the web service can connect to db:5432). Use depends_on to specify startup order, but note it doesn't wait for the service to be ready—add health checks or retry logic in your app. All data in volumes persists until you explicitly remove them.