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

Rob*_*bel 2 docker docker-machine

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

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
Run Code Online (Sandbox Code Playgroud)

kic*_*hik 6

那是HEALTHCHECK指令的结果。该指令每30秒在容器内运行一次命令。如果命令成功,则将容器标记为运行状况良好。如果失败太多次,则标记为不健康。

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

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

HEALTHCHECK --interval=5m --timeout=3s \
  CMD curl -f http://localhost/ || exit 1
Run Code Online (Sandbox Code Playgroud)

health_status健康状况更改时,您会收到一个事件。您可以通过跟随那些和其他人docker events


aja*_*kuv 5

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
Run Code Online (Sandbox Code Playgroud)

看到运行时启用的健康检查了吗?


nas*_*ome 5

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

\n\n

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

\n\n

当容器指定了健康检查时,它除了正常状态之外,还具有健康状态。这种状态是初始状态。每当健康检查通过时,它就会变得健康(无论它之前处于什么状态)。连续失败一定次数后,就会变得不健康

\n\n
**starting**  \xe2\x80\x93 Initial status when the container is still starting\n**healthy**   \xe2\x80\x93 If the command succeeds then the container is healthy\n**unhealthy** \xe2\x80\x93 If a single run of the  takes longer than the specified \n  timeout then it is considered unhealthy. If a health check fails then the \n  will run retries number of times and will be declared unhealthy \n  if the  still fails.\n
Run Code Online (Sandbox Code Playgroud)\n\n

参考

\n