当前可以Dockerfile使用HEALTHCHECK指令在构建映像时指定健康检查。您可以指定要运行的命令、在容器启动后运行第一次检查之前等待的时间 ( --start-period)、运行健康检查的频率 ( --interval)、等待健康检查完成的时间 ( --timeout),以及如果运行状况检查失败,应重试多少次 ( --retries)。这一切都融入到图像中,并且可以在docker inspect本地可用的图像上看到。
但是,似乎没有docker run可以覆盖这些设置的参数。如果您使用的是由执行健康检查的第三方构建的映像,那么您在创建映像时会受到他们决定(或未决定)的影响。例如,当健康检查过早超时时,这可能是一个问题,创建一个孤立进程,该进程将无限期地保留在容器和主机的 PID 表中。由于频繁的健康检查经常超时,PID 表可能会在几天内填满。
有没有办法覆盖图像的健康检查设置,或完全禁用健康检查,而无需重建它?
Izy*_*orr 14
似乎您可以覆盖图像默认值:https : //docs.docker.com/engine/reference/run/#healthcheck
的健康检查参数docker 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
Run Code Online (Sandbox Code Playgroud)
下面是使用时配置健康检查的示例docker-compose.yml。取自 docker 文档。请参阅下面的链接代码
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost"]
interval: 1m30s
timeout: 10s
retries: 3
start_period: 40s
Run Code Online (Sandbox Code Playgroud)
https://docs.docker.com/compose/compose-file/compose-file-v2/#healthcheck
| 归档时间: |
|
| 查看次数: |
5358 次 |
| 最近记录: |