Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork59
How to wait for container X before starting Y using docker-compose healthcheck
License
peter-evans/docker-compose-healthcheck
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Thehealthcheck property was originally introduced in the 2.1 Compose file format and is now part of theCompose Specification used by recent versions of Docker Compose.This allows a check to be configured in order to determine whether or not containers for a service are "healthy."
This is a common problem and in earlier versions of docker-compose requires the use of additional tools and scripts such aswait-for-it anddockerize.Using thehealthcheck parameter the use of these additional tools and scripts is often no longer necessary.
A particularly common use case is a service that depends on a database, such as PostgreSQL.We can configure docker-compose to wait for the PostgreSQL container to startup and be ready to accept requests before continuing.
The following healthcheck has been configured to periodically check if PostgreSQL is ready using thepg_isready command. See the documentation for thepg_isready commandhere.
healthcheck:test:["CMD-SHELL", "pg_isready"]interval:10stimeout:5sretries:5
If the check is successful the container will be marked ashealthy. Until then it will remain in anunhealthy state.For more details about the healthcheck parametersinterval,timeout andretries see the documentationhere.
Services that depend on PostgreSQL can then be configured with thedepends_on parameter as follows:
depends_on:postgres-database:condition:service_healthy
Inthis complete example docker-compose waits for the PostgreSQL service to be "healthy" before startingKong, an open-source API gateway. It also waits for an additional ephemeral container to complete Kong's database migration process.
Test it out with:
docker-compose up -dWait until all services are running:
Test by querying Kong's admin endpoint:
curl http://localhost:8001/MIT License - see theLICENSE file for details
About
How to wait for container X before starting Y using docker-compose healthcheck
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors3
Uh oh!
There was an error while loading.Please reload this page.
