code · Nov 12, 2026

Compose does not wait for PostgreSQL

How to make Docker Compose app container wait until PostgreSQL is ready to accept connections?

Part of Docker Compose: startup, networking and configuration

Symptom: the app container exits with `connection refused` on the database port although `depends_on: db` is set. Cause: plain `depends_on` waits for the container process (`service_started`), not for the database to accept TCP connections. `pg_isready` without a host checks the Unix socket, and the official postgres image runs a socket-only temporary server during initdb, so a socket check can pass before the real server listens. Fix, TCP healthcheck plus `service_healthy`. As `compose.json` (JSON is valid compose YAML, so lost indentation cannot break it): ``` {"services":{"db":{"image":"postgres:16","environment":{"POSTGRES_USER":"appuser","POSTGRES_DB":"appdb","POSTGRES_PASSWORD":"change-me"},"healthcheck":{"test":["CMD-SHELL","pg_isready -h localhost -U appuser -d appdb"],"interval":"10s","timeout":"5s","retries":5,"start_period":"30s"}},"app":{"build":".","depends_on":{"db":{"condition":"service_healthy"}}}}} ``` `-h localhost` forces a TCP check, which only succeeds once the real server listens. `start_period` gives initdb time; it does not make a passing check pass earlier. `build: .` expects a Dockerfile next to the file. Compose only auto-loads its standard filenames, so pass this one explicitly: `docker compose -f compose.json up -d`, then `docker compose -f compose.json ps` shows `db ... (healthy)`.

Query directly via MCP

This blueprint is also machine-readable: Markdown. Create an API key without an account:

curl -sS -X POST https://solvedlist.com/api/v1/keys \
  -H 'Content-Type: application/json' -d '{"note":"agent"}'
POST https://solvedlist.com/mcp
Authorization: Bearer ***
Content-Type: application/json

{"jsonrpc":"2.0","id":1,"method":"tools/call",
 "params":{"name":"solvedlist_lookup","arguments":{"question":"…"}}}

More: /llms.txt · /openapi.json