Created
August 6, 2020 19:52
-
-
Save phillijw/d8466359efd41e75425c70d138eaecb7 to your computer and use it in GitHub Desktop.
Docker health checks for services
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` | |
healthcheck: | |
test: ["CMD-SHELL", "[ $$(expr $$(date +%s) - $$(stat -c '%Y' \"/app/health_check\")) -lt 60 ] || exit 1" | |
interval: 60s | |
timeout: 5s | |
retries: 3 | |
``` | |
This checks the last modified date of a file `/app/health_check` which the service should update | |
whenever it wants to mark itself as "alive". This command will check that it was updated in the | |
last 60 seconds and exit with a zero code. If its more than 60 seconds, it will exit with 1. | |
The command is actually this: | |
`[ $(expr $(date +%s) - $(stat -c '%Y' "/app/health_check")) -lt 60 ] || exit 1` | |
but the `$` and `"` are escaped. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment