Skip to content

Docker Container Healthcheck

Posted on:November 10, 2021 at 06:10 PM

How-to

If you want to use the healthcheck feature for a container. You can use curl for that.

curl -fs http://localhost:8008/health

Where:

user@XX:~$ curl --help
Usage: curl [options...] <url>
 -f, --fail          Fail silently (no output at all) on HTTP errors
 -s, --silent        Silent mode

Dockerfile

You need to enable it via Dockerfile HEALTHCHECK.

HEALTHCHECK --interval=10s --timeout=5s \
  CMD curl -fs http://localhost:8008/health || exit 1

Ad hock

DOCKER CLI RUN

--health-cmd		Command to run to check health
--health-interval		Time between running the check (ms|s|m|h) (default 0s)
--health-retries		Consecutive failures needed to report unhealthy
--health-start-period		API 1.29+
Start period for the container to initialize before starting health-retries countdown (ms|s|m|h) (default 0s)
--health-timeout		Maximum time to allow one check to run (ms|s|m|h) (default 0s)