intermediate

Docker Compose

Model multi-service local stacks with services, networks, volumes, environment files, health checks, and dependency order.

Docker Compose describes a local or small-stack environment: services, networks, volumes, env files, health checks, and startup dependencies. It fits FullStack apps with web, API, database, cache, and workers.

					services:
  api:
    build: .
    depends_on:
      db:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
      interval: 10s
  db:
    image: postgres:16
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U app"]
				

`depends_on` orders startup — it does not guarantee readiness. Use health checks, retrying clients, or migration init containers for real availability.

On interviews: compose versus production orchestrators, health checks versus `depends_on`, env file boundaries, and keeping dev stacks aligned with deploy manifests.

Common pitfalls: treating compose as production orchestration; stacks that diverge too far from Kubernetes or cloud deploy assumptions.

The trade-off is fast local fidelity versus maintaining two environment models.

Checklist:

  • Model real local dependencies.
  • Use health checks for readiness.
  • Keep dev and deploy assumptions aligned.
  • Tear down volumes and networks deliberately.