Restarting an unhealthy docker container based on healthcheck

前端 未结 6 952
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-30 16:31

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 cont

6条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-30 16:42

    You can try put in your Dockerfile something like this:

    HEALTHCHECK --interval=5s --timeout=2s CMD curl --fail http://localhost || kill 1
    

    Don't forget --restart always option.

    kill 1 will kill process with pid 1 in container and force container exit. Usually the process started by CMD or ENTRYPOINT has pid 1.

    Unfortunally, this method likely don't change container's state to unhealthy, so be careful with it.

提交回复
热议问题