How do you set up a health check in Docker for Directus?
Based on https://docs.directus.io/reference/system/server.html#health, my idea was:
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8055/server/health"]
But it fails with the following error, which can be seen by running docker inspect directus-directus-1 | jq '.[].State.Health':
OCI runtime exec failed: exec failed: unable to start container process: exec: \"curl\": executable file not found in $PATH: unknown
Seems there is no curl in the image. That's fine. Instead, we can use wget:
wget --no-verbose --tries=1 --spider 'http://localhost:8055/server/health' || exit 1
Kind of a self-answer. Though, I found opinions that using curl etc. for healthcheck have disadvantages, and it is proposed to have a custom healthcheck built into the app:
- https://www.paulsblog.dev/how-to-successfully-implement-a-healthcheck-in-docker-compose/#6-a-custom-health-check
- https://blog.sixeyed.com/docker-healthchecks-why-not-to-use-curl-or-iwr/
What do respected maintainers and community think about it?
For example, Traefik has a dedicated CLI command: https://doc.traefik.io/traefik/operations/cli/#healthcheck
is still healthy. if not returnign a success code, it will be set as unhealthy. What else do you want to achieve?