根据运行状况检查重启不健康的Docker容器 [英] Restarting an unhealthy docker container based on healthcheck
问题描述
我正在使用 Docker 17.09.0-ce
版本,并且我看到容器被标记为不健康。是否可以选择重新启动容器而不是使容器保持不正常状态?
I am using Docker version 17.09.0-ce
, and I see that containers are marked as unhealthy. Is there an option to get the container restart instead of keeping the container as unhealthy?
推荐答案
重新启动不健康容器功能已在原始PR( https://github.com/moby/moby/pull/22719 ) ,但经过讨论后被删除,并认为稍后将作为RestartPolicy的增强。
Restarting of unhealty container feature was in the original PR (https://github.com/moby/moby/pull/22719), but was removed after a discussion and considered to be done later as enhancement of RestartPolicy.
此刻,您可以使用以下解决方法自动重启不健康的容器: https://hub.docker.com/r/willfarrell/autoheal/
At this moment you can use this workaround to automatically restarting unhealty containers: https://hub.docker.com/r/willfarrell/autoheal/
以下是示例撰写文件:
version: '2'
services:
autoheal:
restart: always
image: willfarrell/autoheal
environment:
- AUTOHEAL_CONTAINER_LABEL=all
volumes:
- /var/run/docker.sock:/var/run/docker.sock
只需对此执行 docker-compose up -d
这篇关于根据运行状况检查重启不健康的Docker容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!