Wait for services (TCP, HTTP, PostgreSQL, Redis) before starting your app
1.9K
Universal service readiness checker for Docker Compose. Wait for databases, APIs, and services to be ready before starting your application.
Docker Compose depends_on only waits for the container to start, not for the service inside to be ready. This image solves the "connection refused" problem once and for all.
services:
db:
image: postgres:17
environment:
POSTGRES_PASSWORD: secret
api:
image: myapp:latest
depends_on:
wait-for-db:
condition: service_completed_successfully
wait-for-db:
image: zachbg/wait-for:latest
command: ["db:5432", "--timeout", "60"]
# Wait for a TCP port
docker run --rm zachbg/wait-for:latest host:port
# Wait for HTTP endpoint
docker run --rm zachbg/wait-for:latest http://api:8080/health
# Wait for multiple services, then run a command
docker run --rm zachbg/wait-for:latest \
db:5432 redis:6379 -- echo "All ready!"
| Scheme | Example | Check |
|---|---|---|
| TCP | host:port | TCP connection |
| HTTP | http://host/path | HTTP 2xx-3xx |
| HTTPS | https://host/path | HTTPS 2xx-3xx |
| PostgreSQL | pg://host:5432 | TCP on 5432 |
| Redis | redis://host:6379 | TCP on 6379 |
| MySQL | mysql://host:3306 | TCP on 3306 |
| Flag | Default | Description |
|---|---|---|
-t, --timeout | 30 | Timeout in seconds |
-i, --interval | 2 | Poll interval in seconds |
-q, --quiet | off | Suppress output |
services:
postgres:
image: postgres:17
environment:
POSTGRES_PASSWORD: secret
healthcheck:
test: ["CMD-SHELL", "pg_isready"]
interval: 5s
timeout: 5s
retries: 5
redis:
image: redis:7-alpine
app:
image: myapp:latest
depends_on:
init:
condition: service_completed_successfully
init:
image: zachbg/wait-for:latest
command: >
pg://postgres:5432
redis://redis:6379
--timeout 120
-- echo "Dependencies ready"
Content type
Image
Digest
sha256:8839455be…
Size
9.5 MB
Last updated
6 months ago
docker pull zachbg/wait-for