Skip to content

Latest commit

 

History

History
149 lines (122 loc) · 2.74 KB

README.adoc

File metadata and controls

149 lines (122 loc) · 2.74 KB

sdavids-docker-healthcheck-shell-nc

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.

1. Format Source Code

$ scripts/format.sh

2. Lint Source Code

$ scripts/lint.sh

3. Usage

  1. Copy the health check into your container:

    Dockerfile
    COPY --chmod=0777 src/healthcheck.sh /usr/local/bin/healthcheck
  2. Configure the health check:

    Dockerfile
    HEALTHCHECK --interval=5s --timeout=5s --start-period=5s \
        CMD healthcheck || exit 1

    More information:

  3. (Optional) Pass the HEALTHCHECK_PORT to the docker container run invocation:

    scripts/docker_start.sh
    docker container run \
    ...
      --env HEALTHCHECK_PORT=8080 \
    ...

    Alternatively, add the HEALTHCHECK_PORT to the Dockerfile:

    Dockerfile
    ENV HEALTHCHECK_PORT=8080

4. Example

Dockerfile: a simple HTTP server

  1. Build the image:

    $ scripts/docker_build.sh
  2. Start a container:

    $ scripts/docker_start.sh
    
    Listen local: http://localhost:3000
    
    The URL has been copied to the clipboard.
  3. 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
  4. Get the health status:

    $ scripts/docker_health.sh
    healthy 0
  5. Stop the container:

    $ scripts/docker_stop.sh
  6. Remove all Docker artifacts related to this project:

    $ scripts/docker_cleanup.sh