Replies: 9 comments
-
Maybe I misunderstand your expectations, but compose does not play an active role during the lifetime of the containers it starts. With your setup the best you can ask from compose is: Furthermore, on the daemons' side - the dockerd/containerd/runc side - there are no reactions to a failing health check ... it's just FYI ... it shows up in PS. when it comes to the syntax for the health check I've not yet been able to remember how to choose between CMD and CMD-SHELL so I always refer to the spec: https://docs.docker.com/compose/compose-file/05-services/#healthcheck PPS. on the good news side there's now support for an initial period and an initial interval for the health checks, which allows for a more ... rapid succession (the initial interval) of ... initial health checks (for a predefined initial period) PPPS. Now that I think of ... your health check could "crash" the application if written to do so :D ... hmm, or set up an up -d cron job ... but ... |
Beta Was this translation helpful? Give feedback.
-
Per the HEALTHCHECK docs you mentioned above, is is stated:
In my years, this sounds like the helthcked mechanism should call the test endpoint regularly to check its status. And everywhere I read about the docker compose helthcked mechanism, I'm reading similar stuff. I'm expecting it to run in a similar way healthcheck is performing in K8s. But this is not what I am observing in my case. If this is not what docker compose helthcked mechanism was intended to do, then the documentation must be updated to reflect that. |
Beta Was this translation helpful? Give feedback.
-
Right after the quoted text comes the description about what docker does with that health check: (it sets an additional status, and please note that the link points to the alternative way to define a health check - at image build time) |
Beta Was this translation helpful? Give feedback.
-
Yes, but before getting to setting of the container status, I am not seeing the test requests hitting the backend in the first place... That is my problem. |
Beta Was this translation helpful? Give feedback.
-
Ah, well, do you have curl installed in the image? Aside that, there's only the issue of getting the syntax right and having your application correctly set the http status so that curl's |
Beta Was this translation helpful? Give feedback.
-
Do I need curl installed on the target container or on the host system? From what I was reading it sounds like I only need it on the host system where the docker daemon is running, as it is the daemon that will run the test. And if it would be a problem with curl not being available, I would have at least, expected some errors from docker to complain about this... |
Beta Was this translation helpful? Give feedback.
-
Of course it's necessary to have it in the container. For CMD-SHELL a shell is necessary too. The health check is very similar with docker exec .... inside a container, and yes, it's really not obvious what's going on behind the scene - maybe logs appear in OS's logs - I never checked that |
Beta Was this translation helpful? Give feedback.
-
here's a quote from that last link:
|
Beta Was this translation helpful? Give feedback.
-
Finally started to work, by installing curl within the container and pointing the test endpoint to the internal port #. So indeed it looks like the check is done from within the container. Thanks for your help! I would say, docs should be updated to make it clear how this mechanism works. |
Beta Was this translation helpful? Give feedback.
-
I am trying to put in place a healthcheck mechanism for one of my containers, but so far, I was not able to make it running.
The container is starting ok, but for I don't know what reasons, docker compose doesn't call the test endpoint (no requests coming from docker compose are hitting my breakpoints), nor is it complaining or restarting the container on which the healthcheck is configured.
There is nothing wrong with the test endpoint, as if I issue curl request from the host system, those requests are visible, when I'm debugging the endpoint.
Any idea why docker compose is not calling the test endpoint?
My docker compose file looks like this:
My docker compose version is: Docker Compose version v2.24.6
My host system is: Fedora release 39
As test parameter, I've already tried, without success, the followings:
Beta Was this translation helpful? Give feedback.
All reactions