Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a healthcheck to the Docker container image #10413

Merged
merged 2 commits into from Feb 25, 2022

Conversation

nineinchnick
Copy link
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
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

core/docker/bin/health-check Outdated Show resolved Hide resolved
core/docker/container-test.sh Outdated Show resolved Hide resolved
core/docker/bin/health-check Outdated Show resolved Hide resolved
core/docker/bin/health-check Show resolved Hide resolved
core/docker/bin/health-check Show resolved Hide resolved
core/docker/bin/health-check Outdated Show resolved Hide resolved
core/docker/container-test.sh Show resolved Hide resolved
@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.

None yet

3 participants