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 (though that particular problem can be mitigated with the --init
flag on docker run
).
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/containers/run/#healthchecks
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