HEALTCHECK command, curl command and HTTP status codes

I have a Kafka Streams application set-up as a service in Docker Compose file where the test command in healthcheck is set-up as curl http://localhost:8080/q/health/ready || exit 1. A few questions on this set-up.

  1. Who executes the wget command - docker on host? If yes, then 8080 in the container must be exposed. Further, wget should be available in the host and not in the container image. Correct?
  2. The test command above means that exit 1 will be run if curl returns non-zero exit code. Whereas, the health-check end-point will respond with a HTTP status code. Where does the translation of HTTP status code or semantics of UP or DOWN into shell exit codes happen?
  3. This link has various return codes from curl. Exit status - Everything curl. I don’t follow why a GET from curl to a simple REST end-point may return any of the non-zero return code and therefore, trigger exit 1.
  4. Conversely, I don’t follow how a GET returning a HTTP status code is translated into a non-zero return code triggering exit 1.

Can you please explain?

I assume you meant curl instead of wget. The process is executed inside the container with whatever USER is declared. The commands executed by the healtcheck must exist in the container.

The exit code of the last command is relevant and either needs to be 0 (=passed) or 1 (=failed).

if curl is able to make the request, the command is considered successful regardless of the http status code, and it exits with exit code 0.

If curl fails to make the request, it will return one of the error codes from the url you shared, but the || exit 1 makes sure that instead of returning any non zero exit code directly, it exits with exit code 1. The || is sh/bash syntax for logical OR, which will be evaluated, if the previous command did not return exist code 0.

1 Like

Thanks.

Thanks.

Clear responses - much appreciated!