qdm12 / deunhealth

Binary program to restart unhealthy Docker containers
MIT License
124 stars 8 forks source link

[Feature] Restart other containers when after an unhealthy one #84

Open simoncaron opened 1 year ago

simoncaron commented 1 year ago

In some cases, I need to restart other containers after deunhealth restarts the one with the deunhealth.restart.on.unhealthy label.

In order to do this, I added a new label deunhealth.restart.with.unhealthy.container which should be applied on containers which must be restarted after deunhealth restarts a monitored one. The value of the label should refer to a deunhealth monitored container.

Ex:

Container_1 has the label deunhealth.restart.on.unhealthy=true Container_2 has the label deunhealth.restart.with.unhealthy.container=Container_1

When Container_1 gets unhealthy, deunhealth will restart it, and will restart Container_2 afterward:

2023-03-10T15:23:03-05:00 INFO Monitoring containers Container_1 to restart when becoming unhealthy
2023-03-10T15:23:03-05:00 INFO container Container_1 (image alpine:3.15) is unhealthy, restarting it...
2023-03-10T15:23:04-05:00 INFO container Container_1 restarted successfully
2023-03-10T15:23:04-05:00 INFO container Container_2 (image alpine:3.15) is linked to unhealthy container Container_1, restarting it...
2023-03-10T15:23:04-05:00 INFO linked container Container_2 restarted successfully