One file, whole stack
Typing long docker run commands for the API, database and cache gets old fast. Docker Compose describes all services, their networks and volumes in compose.yaml; docker compose up -d starts everything, down removes it.
compose.yaml
services:
api:
build: .
ports:
- "3000:3000"
environment:
NODE_ENV: production
DB_HOST: db
depends_on:
- db
db:
image: postgres:16-alpine
environment:
POSTGRES_PASSWORD: example
volumes:
- pgdata:/var/lib/postgresql/data
volumes:
pgdata:
- docker compose up -d --build rebuilds images.
- docker compose logs -f api, exec db psql ….
- down keeps volumes; down -v deletes them too.