A Compose file has `depends_on: [postgres]` with no `condition:`, and the API container crashes on startup roughly one time in five with a connection-refused error, but never on a rerun a moment later. What's the race, and what actually fixes it?
Plain depends_on: [postgres] only guarantees that the Postgres container is started before the API container starts — it says nothing about whether Postgres is actually ready to accept connections yet, and a Postgres process typically takes a few seconds after its own process starts before it's actually listening and accepting. On a fast machine or a lightly loaded one, those few seconds usually pass before the API gets far enough to open its first database connection, which is why the failure looks intermittent rather than constant — it's a genuine race between two independent startup timelines, and the app occasionally wins the race by connecting before the database has caught up. The fix is depends_on: { postgres: { condition: service_healthy } } together with a healthcheck: on the Postgres service (typically pg_isready) — Compose then waits for the health check to actually pass, not just for the process to have started, before starting the API container at all.