Restart policies, and what unhealthy does not do
Select an icon to see what it is.
Step 6 of 6
unhealthy does not restart a container
A failing healthcheck only changes State.Health.Status to unhealthy. In plain Docker nothing restarts the container because of it, so Running stays true and RestartCount stays 0. Swarm replaces unhealthy tasks, and on a single host you need a script or another tool to do it.
$ docker inspect --format '{{.State.Health.Status}} {{.RestartCount}}' <container> PrevNext
docker inspect
{"State": {"Status": "running""Running": true"Health": {"Status": "unhealthy"}}"RestartCount": 0}
Try it yourself
Start a container that always fails and watch it give up.
$ docker run -d --name flaky --restart on-failure:3 alpine sh -c 'exit 1'$ sleep 3$ docker inspect --format '{{.State.Status}} exit={{.State.ExitCode}} restarts={{.RestartCount}}' flaky$ docker rm -f flaky