容器的健康检查机制
了解在dockerfile中容器的健康检查
# 在dockerfile中使用healthcheck指令,声明健康检测配置,用于判断容器主进程的服务状态是否正常,反映容器的实际健康状态。基于这样的dockerfile构建镜像,在基于该镜像启动容器,这样的容器就具备健康状态。能够自动进行健康检查。
[root@hqs-docker yun3-health-test]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0771f0e47266 yun3-health-test "/bin/bash" 16 seconds ago Up 13 seconds (health: starting) mystifying_hopper
[root@hqs-docker yun3-health-test]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0771f0e47266 yun3-health-test "/bin/bash" 33 seconds ago Up 31 seconds (healthy) mystifying_hopper
[root@hqs-docker yun3-health-test]# cat Dockerfile
FROM centos
HEALTHCHECK --interval=15s --timeout=5s --retries=2 CMD curl -f http://www.baidu.com || exit 1
[root@hqs-docker yun3-health-test]#
标签:容器,yun3,health,test,健康检查,docker
From: https://www.cnblogs.com/humlogs/p/18191825