Skip to content

Add a healthcheck to the Docker container image#10413

Merged
findepi merged 2 commits intotrinodb:masterfrom
nineinchnick:healthcheck
Feb 25, 2022
Merged

Add a healthcheck to the Docker container image#10413
findepi merged 2 commits intotrinodb:masterfrom
nineinchnick:healthcheck

Conversation

@nineinchnick
Copy link
Copy Markdown
Member

@nineinchnick nineinchnick commented Dec 26, 2021

By defining a healthcheck command in the container image, users can quickly see if the container is ready to accept requests in the output of docker ps:

% docker ps
CONTAINER ID   IMAGE                      COMMAND                  CREATED         STATUS                            PORTS      NAMES
8c630f90bbbc   trino:368-SNAPSHOT-amd64   "/usr/lib/trino/bin/…"   8 seconds ago   Up 7 seconds (health: starting)   8080/tcp   gifted_gauss
% docker ps
CONTAINER ID   IMAGE                      COMMAND                  CREATED              STATUS                        PORTS      NAMES
8c630f90bbbc   trino:368-SNAPSHOT-amd64   "/usr/lib/trino/bin/…"   About a minute ago   Up About a minute (healthy)   8080/tcp   gifted_gauss

Without this, the STATUS column only shows the uptime.

It also frees uses from having to figure out the exact condition and they can use a generic loop that would wait for the container to be ready, like so:

until docker inspect "${CONTAINER_ID}" --format "{{json .State.Health.Status }}" | grep -q '"healthy"'; do
  sleep 1
done

If the healthcheck fails 3 times, it'll start showing as unhealthy. To see more details about the failure, one would have to run docker inspect $CONTAINER_ID --format "{{json .State.Health}}", or run it one more time as docker exec -it $CONTAINER_ID /usr/lib/trino/bin/health-check.

This healthcheck is enabled by default and can be disabled by adding --no-healthcheck to docker run.

The same healthcheck script could be used in readiness and liveness probes in https://github.com/trinodb/charts

@cla-bot cla-bot bot added the cla-signed label Dec 26, 2021
Copy link
Copy Markdown
Member

@electrum electrum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments, otherwise looks good. Thanks for adding this feature

@nineinchnick nineinchnick force-pushed the healthcheck branch 2 times, most recently from 1c79d2f to 6e6ee42 Compare February 15, 2022 09:43
@nineinchnick nineinchnick requested a review from findepi February 22, 2022 09:00
@nineinchnick nineinchnick force-pushed the healthcheck branch 2 times, most recently from 2cdd937 to eeb52dc Compare February 23, 2022 12:13
@findepi findepi merged commit 50fbb46 into trinodb:master Feb 25, 2022
@findepi findepi mentioned this pull request Feb 25, 2022
@github-actions github-actions bot added this to the 372 milestone Feb 25, 2022
@nineinchnick nineinchnick deleted the healthcheck branch November 2, 2022 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants