Back to Docs
Recipe

Docker Compose Primer

Ship multi-container apps with a single YAML file. No more memorizing long docker run flags.

What is Docker Compose?

Docker Compose lets you define and run multi-container Docker applications. You write a compose.yaml file describing services, networks, and volumes — then spin everything up with a single command.

The Anatomy

services:
  web:
    image: nginx:alpine
    ports:
      - "8080:80"
  api:
    build: ./api
    environment:
      - DATABASE_URL=postgres://...
    depends_on:
      - db
  db:
    image: postgres:16
    volumes:
      - pgdata:/var/lib/postgresql/data

volumes:
  pgdata:

Essential Commands

  • docker compose up -d— start detached
  • docker compose down— tear down
  • docker compose logs -f— tail all services
  • docker compose build --no-cache— fresh rebuild

Pro Tips

  • Use .env files instead of hardcoding secrets in YAML.
  • Pin image digests in production — tags like :latest are reproducibility killers.
  • Healthchecks prevent routing traffic to containers that aren't ready yet.

Ready to go deeper? Read the full Meridian docs for production patterns, networking deep-dives, and CI/CD integration recipes.