Currently I am trying to check if a webservice running inside a docker container is healthy and if its HTTP status code is 200.
But dockers built in healthcheck only checks for exit codes.
I am running this command via terminal:
curl -o /dev/null -s -w "%{http_code}\n" http://localhost:8080/api/health
And check if the returned status code is 200. How can I embed this one inside dockers healthcheck?
You can work with the fact that HEALTHCHECK
only checks the exit code values of a command as follows:
-w
and -s
options in curl
to only output the http status code of the api requestThe HEALTHCHECK
in your Dockerfile might look like this:
HEALTHCHECK --interval=20s --retries=2 CMD \
[[ "$(curl -o /dev/null -s -w "%{http_code}\n" http://localhost:8080/api/health)" == "200" ]]
See documentation here
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