当前,当使用HEALTHCHECK指令构建镜像时,可以在Dockerfile
中指定运行状况检查。您可以指定要运行的命令,在容器启动后运行第一次检查之前等待的时间(--start-period
),运行状况检查的频率(--interval
),等待状况检查完成的时间(--timeout
) ),以及运行状况检查失败后应重试的次数(--retries
)。所有这些都被烘焙到图像中,并且可以通过docker inspect
在本地可用的图像上看到。
但是,docker run
似乎没有可覆盖这些设置的参数。如果您使用的是由第三方执行的用于运行状况检查的图像,则您在创建图像时会受到他们决定(或未决定)的决定。例如,当运行状况检查超时太快而创建一个孤立的进程,该进程将无限期地保留在容器和主机的PID表中时,这可能是一个问题。由于频繁进行的健康检查通常会超时,因此PID表可能会在几天内填满。
有没有办法覆盖图像的运行状况检查设置,或完全禁用运行状况检查,而无需重建它?
最佳答案
似乎您可以覆盖图像默认值:https://docs.docker.com/engine/reference/run/#healthcheckdocker run
的运行状况检查参数为:
--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