Table of Contents
An nc-based Docker health check for a daemon port.
❗
|
The port is probed for a daemon listening. No request is sent therefore no response body or status is evaluated. |
This health check uses the port passed in via the following ENV variable:
HEALTHCHECK_PORT
-
the port to be used for the health check
If HEALTHCHECK_PORT
is not set 3000
will be used.
-
Copy the health check into your container:
DockerfileCOPY --chmod=0777 src/healthcheck.sh /usr/local/bin/healthcheck
-
Configure the health check:
DockerfileHEALTHCHECK --interval=5s --timeout=5s --start-period=5s \ CMD healthcheck || exit 1
More information:
-
(Optional) Pass the
HEALTHCHECK_PORT
to thedocker container run
invocation:scripts/docker_start.shdocker container run \ ... --env HEALTHCHECK_PORT=8080 \ ...
Alternatively, add the
HEALTHCHECK_PORT
to theDockerfile
:DockerfileENV HEALTHCHECK_PORT=8080
Dockerfile: a simple HTTP server
-
Build the image:
$ scripts/docker_build.sh
-
Start a container:
$ scripts/docker_start.sh Listen local: http://localhost:3000 The URL has been copied to the clipboard.
-
Examine the two endpoints:
$ curl -s -o /dev/null -w "%{http_code}" http://localhost:3000 200 $ curl -s -o /dev/null -w "%{http_code}" http://localhost:3000/-/health/liveness 200
-
Get the health status:
$ scripts/docker_health.sh healthy 0
-
Stop the container:
$ scripts/docker_stop.sh
-
Remove all Docker artifacts related to this project:
$ scripts/docker_cleanup.sh