services: postgres: image: postgres:16-alpine restart: unless-stopped environment: # No defaults on purpose: POSTGRES_USER/PASSWORD/DB must be set in your # local, git-ignored .env (see .env.example). Compose fails loudly if # they're missing instead of falling back to a guessable credential. POSTGRES_USER: ${POSTGRES_USER:?set POSTGRES_USER in .env} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD in .env} POSTGRES_DB: ${POSTGRES_DB:?set POSTGRES_DB in .env} ports: - "${POSTGRES_PORT:-5432}:5432" volumes: - postgres_data:/var/lib/postgresql/data healthcheck: test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER"] interval: 5s timeout: 5s retries: 5 api: build: context: . dockerfile: apps/api/Dockerfile restart: unless-stopped depends_on: postgres: condition: service_healthy environment: NODE_ENV: production PORT: 3000 # Uses the "postgres" service name, not localhost/POSTGRES_PORT — # container-to-container traffic stays on the compose network and # always targets Postgres's internal port (5432). DATABASE_URL: "postgresql://${POSTGRES_USER:?set POSTGRES_USER in .env}:${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD in .env}@postgres:5432/${POSTGRES_DB:?set POSTGRES_DB in .env}?schema=public" JWT_SECRET: ${JWT_SECRET:?set JWT_SECRET in .env} CORS_ORIGIN: "http://localhost:${WEB_PORT:-8080}" ports: - "${API_PORT:-3000}:3000" web: build: context: . dockerfile: apps/web/Dockerfile restart: unless-stopped depends_on: - api ports: - "${WEB_PORT:-8080}:80" volumes: postgres_data: