Sign inSign up

zachbg/wait-for

By zachbg

•Updated 6 months ago

Wait for services (TCP, HTTP, PostgreSQL, Redis) before starting your app

Image
1

1.9K

zachbg/wait-for repository overview

⁠Wait-For

Universal service readiness checker for Docker Compose. Wait for databases, APIs, and services to be ready before starting your application.

⁠Why?

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.

⁠Quick Start

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"]

⁠Usage

# 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!"

⁠Supported Protocols

SchemeExampleCheck
TCPhost:portTCP connection
HTTPhttp://host/pathHTTP 2xx-3xx
HTTPShttps://host/pathHTTPS 2xx-3xx
PostgreSQLpg://host:5432TCP on 5432
Redisredis://host:6379TCP on 6379
MySQLmysql://host:3306TCP on 3306

⁠Options

FlagDefaultDescription
-t, --timeout30Timeout in seconds
-i, --interval2Poll interval in seconds
-q, --quietoffSuppress output

⁠Docker Compose Pattern

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"

Tag summary

Content type

Image

Digest

sha256:8839455be…

Size

9.5 MB

Last updated

6 months ago

docker pull zachbg/wait-for