Reputation: 1721
I am running a docker container with health-cmd and I know it will turn to unhealthy when it stops working.
$ docker run
--name=some-container \
--health-cmd='curl -sS http://127.0.0.1:5000 || exit 1' \
--health-timeout=10s \
--health-retries=3 \
--health-interval=5s \
--restart on-failure \
container-image
I want to restart the container when it changes its health-status. How can do that? How to trigger the restart?
My Docker version 19.03.1, build 74b1e89
Upvotes: 2
Views: 2076
Reputation: 18608
depends on your Dockerfile
if the health check
faild the container is exited with the code 1
becaus of your command :
--health-cmd='curl -sS http://127.0.0.1:5000 || exit 1'
therefore your restart policy on-failure
will restart the container
after ~35 seconds timeout + retries + interval
when only the check failed.
the timeout + retries + interval
values you can determind on many conditions there is no perfect values for them.
I think your command are good to go
Upvotes: 1
Reputation: 7157
You can use autoheal to restart unhealthy docker containers. Sample:
docker run -d \
--name autoheal \
--restart=always \
-e AUTOHEAL_CONTAINER_LABEL=all \
-v /var/run/docker.sock:/var/run/docker.sock \
willfarrell/autoheal
Note: You must apply HEALTHCHECK to your docker images first. See https://docs.docker.com/engine/reference/builder/#healthcheck for details.
Upvotes: 0