We are using healthchecks in Docker compose files ( version 3.4 ). We run Docker stack deploy in a single host swarm mode. If one container is unhealthy we would like to restart all containers. Is there any way to do this in an automated way, Docker swarm mode only restarts the unhealthy container?
Hi, Thanks
I assume you mean we need our own script that monitors the events and then calls the API to do this. We were wondering whether there was any settings in the compose file or something that was all.
On my own, I cannot assert there is no such setting in compose file for this. If it were, I’d expect it to be in the compose reference document. You don’t say whether you read that or not.
[I admit to having a limited imagination. I wonder why the healthy parts of a cluster should restart to cause recover of the unhealthy one. Is there something else you are after?]
This solution risks to contradict one of the major benefits with cloud and multiple containers. The term “pets vs. cattle” attempts to describe how large applications used to be treated as “pets” (“I always make sure my pet is alive and well”) whereas today’s applications may be distributed across many containers and therefore treated as cattle (“There are so many, I don’t care if a few die”).
If you kill all your containers if only one is misbehaving, you might end up in the old “pet” way of thinking.
Just my 2 ¢
@hannesmvw warnings aside, just to answer the question on its technical face:
A process can listen to docker events and run a script that restarts services when a container is unhealthy. The script can use ‘docker service update --force ${servicename}’