Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to modify docker health check without rebuilding image?

Tags:

docker

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?

like image 792
kbolino Avatar asked Dec 14 '18 01:12

kbolino


2 Answers

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
like image 50
Izydorr Avatar answered Sep 24 '22 00:09

Izydorr


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

like image 24
villaa19 Avatar answered Sep 27 '22 00:09

villaa19