Skip to content

⏳ Docker container that puts itself on hold until the other services are accessible via TCP

License

Notifications You must be signed in to change notification settings

drevops/docker-wait-for-dependencies

Repository files navigation

Wait for dependencies logo

Docker wait for dependencies

GitHub Issues GitHub Pull Requests Test codecov GitHub release (latest by date) LICENSE Renovate

Docker Pulls amd64 arm64


Container to wait for container healthchecks before proceeding with the stack start
Available for linux/amd64 and linux/arm64 architectures.

Features

  • TCP connectivity: Wait for services to be accessible via TCP (using host:port format)
  • Shell command: Execute arbitrary shell commands and wait for successful completion
  • Configurable timeouts: Customizable sleep intervals and timeout periods
  • User-friendly output: Clear progress indicators and status messages
  • Multi-architecture support: Available for linux/amd64 and linux/arm64

Example usage:

TCP Connectivity

Wait for services to accept TCP connections on specific ports:

services:
  database:
    image: postgres:15-alpine
    environment:
      POSTGRES_PASSWORD: secret
    ports:
      - "5432:5432"

  cache:
    image: redis:7-alpine
    ports:
      - "6379:6379"

  app:
    image: alpine:3.22
    depends_on:
      # Will start only after the wait-for-dependencies finishes waiting
      # for both database and cache to be reachable.
      wait-for-dependencies:
        condition: service_completed_successfully
    ports:
      - "8000:8000"

  wait-for-dependencies:
    image: drevops/docker-wait-for-dependencies:25.9.0
    depends_on:
      - database
      - cache
    command: database:5432 cache:6379

Combined TCP and Health Check Commands

Wait for both TCP connectivity and custom health check endpoints:

services:
  api:
    image: php:8.3-cli-alpine
    ports:
      - "8080:8080"
    command: php -S 0.0.0.0:8080 -t /app

  worker:
    image: alpine:3.18
    ports:
      - "9000:9000"
    command: nc -l -p 9000

  app:
    image: alpine:3.22
    depends_on:
      # Will start only after the wait-for-dependencies finishes waiting
      # for both api and worker to be reachable.
      wait-for-dependencies:
        condition: service_completed_successfully
    ports:
      - "8000:8000"

  wait-for-dependencies:
    image: drevops/docker-wait-for-dependencies:25.9.0
    depends_on:
      - api
      - worker
    command:
      - api:8080
      - worker:9000
      - "curl -f http://api:8080/health"
      - "test -S /var/run/app.sock"

Configuration

The container supports the following environment variables:

Variable Default Description
SLEEP_LENGTH 2 Time (in seconds) to wait between each check attempt
TIMEOUT_LENGTH 300 Maximum time (in seconds) to wait before giving up
SUMMARY_ENABLED true Show summary message when all checks complete successfully

Development & Maintenance

npm run lint # Lint shell scripts and Dockerfile
npm run lint-fix # Auto-fix formatting issues
npm run test-unit # Run unit tests for validation logic
npm run test-functional # Run end-to-end tests with Docker

Versioning

This project uses CalVer versioning:

  • YY: Last two digits of the year, e.g., 25 for 2025.
  • m: Numeric month, e.g., April is 4.
  • patch: Patch number for the month, starting at 0.

Example: 25.4.2 indicates the third patch in April 2025.

Releasing

Releases are scheduled to occur at a minimum of once per month.

The cross-platform images are built by GitHub actions and pushed to DockerHub:

  • YY.m.patch tag - when release tag is published on GitHub.
  • latest - when release tag is published on GitHub.
  • canary - on every push to main branch

Dependencies update

Renovate bot is used to update dependencies. It creates a PR with the changes and automatically merges it if CI passes. These changes are then released as a canary version.


This repository was created using the Scaffold project template

About

⏳ Docker container that puts itself on hold until the other services are accessible via TCP

Resources

License

Stars

Watchers

Forks

Sponsor this project

  •  

Contributors 3

  •  
  •  
  •