How can we do healthcheck for docker compose setup for Questdb.
The default image does not have ps
, nc
, wget
, curl
or pgrep
.
Is there any easy way to do a check or this?
Thanks
This one was fun to reply :)
First make sure you are starting the container with the health check and metrics (if needed) endpoints enabled passing the env variables, as in:
docker run -p 9000:9000 -p 9003:9003 -e QDB_METRICS_ENABLED=true -e QDB_HTTP_MIN_ENABLED=true questdb/questdb:latest
You don't actually need to expose port 9003 if you want to test only from inside docker.
Now, how can you test from the same container with no curl or wget? I tried with java, which is available on the /application/bin folder of the image, but no java compiler there.
But it turns out we have Perl, so you can do:
perl -e 'use IO::Socket::INET; $|=1; $socket = IO::Socket::INET->new(PeerAddr=>"localhost:9003"); print $socket "GET / HTTP/1.0\r\nHost: localhost:9003\r\n\r\n"; while(<$socket>) { print $_; }'
You should get the output of the healtcheck
If you want the full metrics, just use localhost:9003/metrics instead
And if you wanted just exit(0)
or exit(1)
depending on status you could do something similar to
perl -e 'use IO::Socket::INET; $socket = IO::Socket::INET->new(PeerAddr=>"localhost:9003") or exit 1; print $socket "GET / HTTP/1.0\r\nHost: localhost:9003 \r\n\r\n"; $response = <$socket>; if ($response =~ /HTTP\/1\.[01] 2\d\d/) { exit 0; } else { exit 1; }'