I have a Docker Compose stack running on an Amazon EC2 instance, and I am just now learning you can have a health check directly inside a Dockerfile, so I want to add it to one of my images like this example I saw:
HEALTHCHECK CMD curl --fail http://localhost:8080/health || exit 1
Who actually runs the curl command to see if the service is up? Is it:
If it is 1, should this not be http://<service-name>:8080/health instead? Is it better to use localhost, 127.0.0.1 or service-name in a Dockerfile like this? is there a convention?
Dockerfiles provides a way to perform docker container health check as well as docker compose which allows to set healthcheck for the services that compose the application from the docker-compose.yml file, starting from version 2.1.
In both cases, from Dockerfiles or docker compose, the health checks are performed by the Docker daemon which invokes this command every 30 seconds and it determines if a container is healthy.
In particular, the healthcheck result is displayed in the STATUS column of the docker ps command and may have the results:
Please, refer to the official documentation https://docs.docker.com/engine/reference/builder/#healthcheck.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With