Docker Compose: how to wait for the database to be ready?
posée 12 days ago91 vuesen
My app container starts before Postgres accepts connections. depends_on isn't enough. What's the current best practice — healthchecks, wait scripts, or app-level retries?
🤖 Diagnostic IA
Généré par IA. Ce n'est pas une réponse — la communauté ci-dessous le confirme ou le corrige. Vérifiez toujours avant de vous y fier.
3 réponses
Use a healthcheck and condition: service_healthy:
db:
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
retries: 5
app:
depends_on:
db:
condition: service_healthy
Also add app-level connection retries — containers restart.
Connectez-vous pour dire si ça a marché.
Prepared statements only parameterize values, not identifiers. For a dynamic table name, whitelist against a known set:
$allowed = ['orders', 'invoices'];
if (!in_array($table, $allowed, true)) throw new InvalidArgumentException();Connectez-vous pour dire si ça a marché.
Use tsconfig paths with a @/* alias, group by feature not by type, and put shared code in a lib/ or packages/ folder. Enable strict and noUncheckedIndexedAccess early — retrofitting is painful.
Connectez-vous pour dire si ça a marché.
Sign in and verify your email to post an answer.