Area 07 · Deployment · Concept 02 of 20

Docker Compose

Run several containers together (API, database, Redis) from one file.

01–10 · The basePhase 5 · Weeks 18–20≈ 1 hour

The idea

Real apps are several services: your API, Postgres with pgvector, Redis, a worker, maybe Langfuse. Docker Compose describes them in one YAML file with their images, ports, environment, volumes and dependencies, and starts them all with one command.

Services reach each other by name on a private network (the API connects to postgres:5432). Named volumes keep database data between restarts. Health checks plus depends_on make services wait until the database is ready.

Compose is ideal for local development and simple single-server deployments; larger systems move to managed services or Kubernetes.

Why it matters

It lets anyone run your full stack with docker compose up, which makes your portfolio projects easy to try.

Words to know

  • ServiceOne container definition in a Compose file.
  • VolumePersistent storage outside the container’s lifecycle.

Try it without code

Start a stack

  1. Save the example below as compose.yaml.
  2. Run docker compose up -d.
  3. Run docker compose ps and docker compose logs api.

Use it in code

API + pgvector + Redis + worker.

yaml
services:
  db:
    image: pgvector/pgvector:pg16
    environment: { POSTGRES_PASSWORD: pw }
    volumes: [pgdata:/var/lib/postgresql/data]
    healthcheck: { test: ["CMD", "pg_isready", "-U", "postgres"], interval: 5s, retries: 10 }
  redis:
    image: redis:7
  api:
    build: .
    env_file: .env
    environment: { DATABASE_URL: "postgresql://postgres:pw@db:5432/postgres", REDIS_URL: "redis://redis:6379" }
    ports: ["8000:8000"]
    depends_on: { db: { condition: service_healthy }, redis: { condition: service_started } }
  worker:
    build: .
    command: ["rq", "worker", "ingest", "--url", "redis://redis:6379"]
    env_file: .env
    depends_on: [redis, db]
volumes:
  pgdata:
PRACTICE · TICK IT AFTER THIS

Write a compose.yaml for your RAG app so a stranger can clone the repo and run everything with one command.

Common mistakes

  • Using localhost inside containers to reach another service.
  • No volume, so the database resets every restart.

Go deeper