简体   繁体   中英

HEALTHCHECK: Dockerfile vs docker-compose.yml

We are deploying our services using a Docker Compose file and 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.

I feel like I've read through all available documentation, but couldn't find anything.

docker-compose.yml

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

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.

Compose files are usually less shared than the actual docker images they run. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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