24

What does the "(healthy)" string in STATUS column stands for?

user@user:~# docker ps

CONTAINER ID  IMAGE   COMMAND  CREATED   STATUS                   PORTS  NAMES

X             X       X        X         Up 20 hours              X      X

X             X       X        X         Up 21 hours (healthy)    X      X
Robert Wróbel
  • 345
  • 1
  • 2
  • 9

3 Answers3

29

That's the result of the HEALTHCHECK instruction. That instruciton runs a command inside the container every 30 seconds. If the command succeeds, the container is marked healthy. If it fails too many times, it's marked unhealthy.

You can set the interval, timeout, number of retries and start delay.

The following instruction for a Dockerfile, for example, will check that your container responds to HTTP every 5 minutes with a timeout of 3 seconds.

HEALTHCHECK --interval=5m --timeout=3s \
  CMD curl -f http://localhost/ || exit 1

You get a health_status event when the health status changes. You can follow those and others with docker events.

Victor Yarema
  • 1,183
  • 13
  • 15
kichik
  • 33,220
  • 7
  • 94
  • 114
7

https://ryaneschinger.com/blog/using-docker-native-health-checks/

Normally it's something you launch with, to enable swarm or other services to check on the health of the container.

IE:

$ docker run --rm -it \
     --name=elasticsearch \
     --health-cmd="curl --silent --fail localhost:9200/_cluster/health || exit 1" \
     --health-interval=5s \
     --health-retries=12 \
     --health-timeout=2s \
     elasticsearch

see the health checks enabled at runtime?

ajankuv
  • 499
  • 3
  • 22
5

Means they are using the command: healthcheck

https://docs.docker.com/engine/reference/builder/#healthcheck

When a container has a healthcheck specified, it has a health status in addition to its normal status. This status is initially starting. Whenever a health check passes, it becomes healthy (whatever state it was previously in). After a certain number of consecutive failures, it becomes unhealthy.

**starting**  – Initial status when the container is still starting
**healthy**   – If the command succeeds then the container is healthy
**unhealthy** – If a single run of the  takes longer than the specified 
  timeout then it is considered unhealthy. If a health check fails then the 
  will run retries number of times and will be declared unhealthy 
  if the  still fails.

Reference

nasatome
  • 521
  • 6
  • 13