Everything together
Write the Compose file a small production server would run: a public nginx in front, the API behind it, Postgres with persistent data, health checks controlling start-up order, automatic restarts and secrets from an env file.
The production stack
This file is a realistic starting point for a small production server.
The capstone stack has three services with clear roles. nginx is the only service with a published port. The API runs a pinned image version, reads its secrets from an env file and waits for a healthy database. Postgres keeps its files in a named volume and reports its health with pg_isready. Every service restarts automatically unless you stop it.
- db — postgres:16-alpine, env_file, volume pgdata, healthcheck pg_isready -U postgres.
- api — pinned image tag, env_file, depends_on db with condition: service_healthy.
- web — nginx with your config, ports 80:80, depends_on api.
- Every service: restart: unless-stopped.
Only web publishes a port. The database and API are reachable only on the project's private network.