Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to wait for container X before starting Y using docker-compose healthcheck

License

NotificationsYou must be signed in to change notification settings

peter-evans/docker-compose-healthcheck

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Actions Status

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

How can I wait for container X before starting Y?

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.

Waiting for PostgreSQL to be "healthy"

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

Waiting for PostgreSQL before starting Kong

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 -d

Wait until all services are running:

Demo

Test by querying Kong's admin endpoint:

curl http://localhost:8001/

License

MIT License - see theLICENSE file for details

About

How to wait for container X before starting Y using docker-compose healthcheck

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Contributors3

  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp