A simple http healthcheck is not working

Hi,

i have a docker-compose file with several simple http healthchecks like these:

healthcheck:
      test: "curl --fail http://localhost:8080/health/  || exit 1"

but all of them report ‘unhealthy’

Am I missing something here?

Hello Jack,

a working healthcheck for my NginX-container looks this way:

    healthcheck:
      test: service nginx status || exit 1
      interval: 15s
      timeout: 3s
      retries: 2

But even if I remove the lines starting with interval, timeout and retries it is working as expected - container marked as healthy after some time.

I have successfully tested my Nginx-container (where curl is available) with this healthcheck-line:

    healthcheck:
      test: "curl --silent --fail http://localhost/ > /dev/null || exit 1"

So I guess the problem is somewhere else.

  • So please ensure that curl is available within the container.
  • What happens if you run the curl...-command at the container’s shell? What is the exit-code of your curl-command if you run it at the container’s shell? The last-command’s exit-code can be printed with echo $?
1 Like

I found the cause(s) and now all healthcheck are green:

  1. please note that after updating the healthcheck on must stop & remove the container in order to active the change
  2. most images don’t have curl and/or wget. Check and install via apt-get install if needed

This answer helped me a lot, I was using an Alpine image. By default ‘curl’ isn’t installed, changing into a wget request fixed the issue.