App to Restart Unhealthy Docker Container

One of the odd features left out of the Docker ecosystem is restart on unhealthy. Docker knows the status of individual containers, but it somehow does not natively support the feature. There are yaml tricks to have a container kill itself if unhealthy, so the Docker engine restarts it based on the policy. The tool I am recommending is a more comprehensive, if not more commonly recommended, method.

Docker Autoheal is an open source Docker container that, once set up, will monitor and restart other unhealthy containers. In my particular use case, the containers that often do go unhealthy are Gluetun VPN containers, since the providers prioritize fleet availability over single-connection stability. In an ideal configuration, Gluetun containers would reconnect once they find themselves to be “unhealthy” (must be defined separately in yaml), but other containers that were using the tunnel also need to be restarted. Autoheal can manage both.

For obvious reasons, Autoheal is not meant to be used outside of small-scale deployments, maybe home labs and small offices. The idea, as far as I can tell, is that a healthcheck is only meant to report status from the container; acting on it is something else’s or someone else’s job. Native restart on unhealthy was proposed alongside healthchecks but didn’t make the cut. In my particular setting, an enthusiast’s home lab, wiring different containers up for Autoheal is plenty enough.

Leave a comment

Comments will be automatically closed after 30 days.