It is currently possible to specify a health check in the Dockerfile
when building an image with the HEALTHCHECK instruction. You can specify a command to run, the amount of time to wait before running the first check after the container starts (--start-period
), how often to run the health check (--interval
), how long to wait for the health check to complete (--timeout
), and how many times the health check should be retried if it fails (--retries
). This all gets baked into the image and can be seen with docker inspect
on an image that's available locally.
However, there appear to be no arguments to docker run
that can override these settings. If you're using an image built by a third party that performs a health check, you're at the mercy of what they decided (or didn't decide) when creating the image. This can be a problem when, for example, the health check times out too soon, creating an orphaned process that will remain in the PID table of the container and the host machine indefinitely. With frequent health checks that often time out, the PID table can fill up in a matter of days.
Is there a way to override an image's health check settings, or disable the health check entirely, without rebuilding it?
It seems that you CAN override the image defaults: https://docs.docker.com/engine/reference/run/#healthcheck
The healthcheck arguments to docker run
are:
--health-cmd Command to run to check health
--health-interval Time between running the check
--health-retries Consecutive failures needed to report unhealthy
--health-timeout Maximum time to allow one check to run
--health-start-period Start period for the container to initialize before starting health-retries countdown
--no-healthcheck Disable any container-specified HEALTHCHECK
Below is an example when configuring healthcheck when using docker-compose.yml
. Taken from the docker documentation. See link below code
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost"]
interval: 1m30s
timeout: 10s
retries: 3
start_period: 40s
https://docs.docker.com/compose/compose-file/compose-file-v2/#healthcheck
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With