Sikau

DevOps and deployment · Day 14 · about 55 min

Capstone: The production stack

nginx, API and Postgres with health-gated startup, restarts, volumes and env files.

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.

The rest of this lesson

  • Health-gated start-upexplain
  • Prove it on a fresh machineexplain
  • Setting for each guaranteematch
  • Start-up orderorder
  • compose.yamlchallenge
  • Badge quizquiz
  • DevOps course complete!recap

Continue this lesson free — run real code in your browser

Continue with Google

See all 14 lessons of DevOps and deployment