STATUS中的“(健康)”字符串代表什么?

问题描述 投票:2回答:3

STATUS列中的“(健康)”字符串代表什么?

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
docker docker-machine
3个回答
5
投票

这是HEALTHCHECK instruction的结果。该指令每隔30秒在容器内运行一个命令。如果命令成功,则容器标记为正常。如果它失败了太多次,它就会被标记为不健康。

您可以设置间隔,超时,重试次数和启动延迟。

例如,以下内容将检查您的容器每5分钟响应一次HTTP,超时为3秒。

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

当健康状况发生变化时,您会收到health_status事件。您可以使用docker events关注这些人和其他人。


2
投票

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

通常情况下,它是您启动的东西,以使swarm或其他服务能够检查容器的健康状况。

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

看到运行时启用的运行状况检查?


0
投票

意味着他们正在使用命令:healthcheck

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

当容器指定了运行状况检查时,除了正常状态外,它还具有运行状况。此状态最初开始。每当健康检查通过时,它就会变得健康(无论以前处于什么状态)。经过一定数量的连续失败后,它变得不健康。

**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

© www.soinside.com 2019 - 2024. All rights reserved.