Docker Compose: how to wait for the database to be ready?
poze 12 days ago90 gadeen
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?
🤖 Dyagnostik IA
Se IA ki fè l. Se pa yon repons — kominote a anba a konfime oswa korije l. Toujou verifye anvan ou fye l.
3 Repons
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.
Konekte pou di lòt moun si li te mache.
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();Konekte pou di lòt moun si li te mache.
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.
Konekte pou di lòt moun si li te mache.
Sign in and verify your email to post an answer.