Member-only story

HEALTHCHECK in Docker

Park Sehun
3 min readAug 9, 2023

In Docker, a health check is a feature that allows you to periodically check the status of a container and determine if it is in a healthy state. It helps ensure that the container is functioning correctly and ready to handle requests or perform its intended tasks.

FROM busybox

HEALTHCHECK --interval=5s CMD ping -c 1 172.17.0.2

If you build the image and run it, then the result will be like below. You can find the additional field (health: <status>)

Options

The options specified are:

  • --interval=30s: Specifies the interval at which the health check command is executed. (Default 30s)
  • --timeout=10s: Sets the maximum amount of time allowed for the health check command to complete. (Default 30s)
  • --start-period=0s
  • --retries=3: Specifies the number of consecutive failures allowed before considering the container as unhealthy.

This means “I will do every 30s health check and retry three times before reporting”

Exit status:

  • 0: Success: the container is healthy and ready for use
  • 1: Failure: the container is not working correctly
  • 2: Reserved

No responses yet

Write a response