After enabling Compose health checks with `depends_on: condition: service_healthy`, the dependent service still occasionally fails to connect to the database on startup.
Check whether the HEALTHCHECK's test command actually verifies the same thing the dependent service needs (e.g., the healthcheck might just check 'is Postgres accepting TCP connections' while the actual issue is a specific schema/migration not yet applied); also verify the healthcheck's `start_period`/`interval`/`retries` give enough time for true readiness, and consider adding application-level retry-with-backoff logic for the connection itself as defense in depth rather than relying solely on orchestration-level sequencing.
Ready to master this question?
Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.
Sign in to generate a response