Neither the db (postgres:16-alpine) nor api service in docker-compose.yml defines a healthcheck: block, so depends_on: [db] only waits for the container to start, not for Postgres to actually be ready to accept connections — the API can attempt to connect and fail on cold start.
Add a pg_isready-based healthcheck for db and a curl /health-based healthcheck for api, then use depends_on: condition: service_healthy.
Neither the
db(postgres:16-alpine) norapiservice indocker-compose.ymldefines ahealthcheck:block, sodepends_on: [db]only waits for the container to start, not for Postgres to actually be ready to accept connections — the API can attempt to connect and fail on cold start.Add a
pg_isready-based healthcheck fordband acurl /health-based healthcheck forapi, then usedepends_on: condition: service_healthy.