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.
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
- Save the example below as compose.yaml.
- Run docker compose up -d.
- Run docker compose ps and docker compose logs api.
Use it in code
API + pgvector + Redis + worker.
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: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.