notes on infra

2026-01-22 · ops

docker compose depends_on with healthchecks

The simple depends_on: [db] only waits for the container to start, not for the service inside to be ready. For postgres / mysql this is almost always the wrong behaviour — your app crashes on first boot trying to connect to a db that's still initializing.

What actually works in compose v2:

services:
  db:
    image: mariadb:11
    healthcheck:
      test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
      interval: 10s
      timeout: 5s
      retries: 6
      start_period: 30s
  app:
    depends_on:
      db:
        condition: service_healthy

Key bit is condition: service_healthy. Without it, app starts in parallel with db.

For mariadb specifically, the bundled healthcheck.sh handles all the edge cases (still-initializing innodb, password not yet set, etc). For postgres use pg_isready.