Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Who runs the healthcheck? Compose or the container itself?

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:

  1. Docker Compose running the curl command from outside the container; or
  2. the container itself, i.e. curl command runs inside the container?

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?

like image 931
yen Avatar asked Jan 19 '26 11:01

yen


1 Answers

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:

  • 0 healthy container
  • 1 unhealthy container

Please, refer to the official documentation https://docs.docker.com/engine/reference/builder/#healthcheck.

like image 144
Alez Avatar answered Jan 21 '26 02:01

Alez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!