DELAPARRA
Index
Color
NL
Category: Docker

healthcheck (compose)

Explained by Updated

What is healthcheck (compose)?

healthcheck (compose): Defines a health probe for a service directly in the Compose file, overriding any in the image. In Docker Compose, healthcheck defines how to test whether a service is ready, directly in the Compose file. For a PostgreSQL service, pg_isready is a common test; for MySQL, mysqladmin ping. It overrides any health check in the image, and it is what makes depends_on with condition: service_healthy work. Your app container then waits until the database really accepts connections, instead of crashing on start-up.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about healthcheck (compose)

What should you keep in mind with healthcheck (compose)?

Set interval, timeout, retries and start_period to fit the service. Databases can take a while to start, especially the first time when they initialise their data folder, so a generous start_period avoids false failures. docker compose ps shows the health status of each service, which is the first thing to check when a stack does not come up properly.

What does an example of healthcheck (compose) look like?

services: db: image: postgres:16 healthcheck: test: ["CMD-SHELL", "pg_isready -U postgres"] interval: 10s retries: 5

At a glance

CategoryDocker
Explained by
Updated

More Docker terms

All terms starting with H

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.