Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HEALTHCHECK: Dockerfile vs docker-compose.yml

Tags:

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 
like image 546
kev Avatar asked Nov 27 '17 22:11

kev


People also ask

Should I use Dockerfile or Docker compose?

The key difference between the Dockerfile and docker-compose is that the Dockerfile describes how to build Docker images, while docker-compose is used to run Docker containers.

Do I need both Dockerfile and Docker compose yml?

Docker compose uses the Dockerfile if you add the build command to your project's docker-compose. yml. Your Docker workflow should be to build a suitable Dockerfile for each image you wish to create, then use compose to assemble the images using the build command.

What is healthcheck in Dockerfile?

Docker Dockerfiles HEALTHCHECK Instruction The HEALTHCHECK instruction tells Docker how to test a container to check that it is still working. This can detect cases such as a web server that is stuck in an infinite loop and unable to handle new connections, even though the server process is still running.

Does Docker compose replace Dockerfile?

No, Dockerfile instructs Docker how to build your image(s). Docker Compose instructs Docker how to run your image(s). Thx, so I have to make a dockerfile just to have the copy command ?


1 Answers

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.

like image 128
yamenk Avatar answered Sep 22 '22 15:09

yamenk