简体   繁体   English

HEALTHCHECK:Dockerfile与docker-compose.yml

[英]HEALTHCHECK: Dockerfile vs docker-compose.yml

We are deploying our services using a Docker Compose file and Docker Swarm. 我们正在使用Docker Compose文件和Docker Swarm部署我们的服务。 I was wondering if there is any difference between putting the healthcheck inside the Dockerfile or if it is better to put it in the docker-compose.yml. 我想知道将健康检查放在Dockerfile中是否有任何区别,或者将它放在docker-compose.yml中是否更好。

I feel like I've read through all available documentation, but couldn't find anything. 我觉得我已经阅读了所有可用的文档,但找不到任何内容。

docker-compose.yml 泊坞窗,compose.yml

healthcheck:
    test: ["CMD", "curl", "-f", "http://localhost:8081/ping"]
    interval: 30s
    timeout: 10s

Dockerfile Dockerfile

HEALTHCHECK --interval=30s --timeout=10s CMD curl -f http://localhost:8081/ping

Adding health check to the Dockerfile, will make the health-check part of the image, so that anyone pulling the image from the registry will get the health check by default. 向Dockerfile添加运行状况检查将生成映像的运行状况检查部分,以便从注册表中提取映像的任何人都将默认进行运行状况检查。

Compose files are usually less shared than the actual docker images they run. 撰写文件通常不如它们运行的​​实际docker镜像共享。 The dockercompose health-check allows adding/overrriding healthchecks for images for someone who is not creating the image but rather is pulling it from a remote registry. dockercompose运行状况检查允许为未创建映像但是从远程注册表中提取映像的人添加/覆盖图像的运行状况检查。 It is more suitable in situations where the pulled image doesn't have a health-check by default. 它更适用于拉出的图像默认情况下没有健康检查的情况。

In your case, since you are creating the image, adding the health-check to the dockerfile makes more sense. 在您的情况下,由于您正在创建映像,因此将健康检查添加到dockerfile更有意义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM