Compose file with a healthcheck and dependency order

Yaml

Makes the app wait until Postgres actually answers, not merely until its container has started.

services:
  db:
    image: postgres:17
    environment:
      POSTGRES_PASSWORD: example
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 5s
      retries: 10

  app:
    build: .
    depends_on:
      db:
        condition: service_healthy

More in Containers

Random picks