DockerSelf-Hosting

docker-autoheal with Docker: Restart Containers That Turn Unhealthy (Linux, Windows, Mac)

Before you start

  • 18 min read

Boxes marked Run in terminal are what you type; plain text explains why. Check what you need first

What you get in one minute#

docker-autoheal (image willfarrell/autoheal) is a tiny watchdog container that asks Docker every few seconds which containers are unhealthy and restarts the ones you labelled autoheal=true. Docker itself never does that: it only records the health state.

docker-autoheal title card (no official logo)

Image: DIY Lab Hub title card. docker-autoheal has no official logo.

A web app can hang while its process keeps running. Docker's restart policies (restart: unless-stopped) only react when a container exits, so a hung app stays hung. A healthcheck plus autoheal restarts it. That suits stateless homelab apps, not databases.

WhatValue (official sources, read 3 December 2026)
Projectwillfarrell/docker-autoheal, licence MIT (copyright 2018)
ReleasesNo GitHub release. The newest git tag is v0.7.0
Docker Hub tags1.2.0 (pushed 8 July 2021), 1.1.0, 1.0.0, v0.7.0, and latest, rebuilt daily (last push 2 December 2026)
Last code changeMerged 9 September 2025 (a shellcheck clean-up)
Image to pinThe digest of the current build (Step 2)
Time neededAbout 25 minutes (our estimate)
PortsNone
Official docsThe README only

An honest status. The image is rebuilt daily, but the code is not changing. A user asked on 14 November 2026 "Is this project being maintained anymore?" (issue 156, no answer), and in May 2026 a reader explained that the daily push is an automatic job (issue 150). The base is Alpine 3.18, end of life since May 2025 (issue 154, open). The tool is tiny and still works for many people, so we teach it with its limits stated.

At a glance:

  • What it is: one container with a shell script, curl and jq. No web page, no login.
  • What it needs: a healthcheck on each app, and the Docker socket.
  • What it does not do: fix the cause, stop restart loops, or count restarts.
  • Pairs with: Dozzle to read the logs of a container that keeps failing.

How it fits together#

Docker runs your healthcheck inside the app and keeps the verdict. Autoheal reads that verdict through the Docker socket and asks Docker to restart unhealthy containers that carry the label. Fixing the real cause stays your job.

docker-autoheal flow: the autoheal container polls the Docker Engine through the socket and asks which labelled containers are unhealthy, the Docker Engine runs the healthcheck inside your app container and restarts it on request, and an optional webhook message reaches you so that you fix the real cause

Drawn for this guide from the README and the script. The dashed step is manual: autoheal never fixes the cause.

Before you start#

Note: every value on this page is a dummy example (like change-me or hooks.example.com). Replace it with your own and keep real secrets out of Git.

SystemWhat to have
LinuxDocker Engine and the Compose plugin
WindowsWindows 10 or later, Docker Desktop (WSL 2, Linux containers), PowerShell
MacDocker Desktop, Intel or Apple Silicon
Run in terminalbash
docker --version
docker compose version
  • [ ] Both commands print a version
  • [ ] The container you want to protect is not a database, and its image has curl or wget
  • [ ] Its Compose file is backed up

Tested by DIY Lab Hub: not yet. Commands come from the README, the script at commit f535158 and the Docker documentation, read on 3 December 2026. We did not run them on a real machine.

Step 1: Learn the healthcheck basics and inspect yours#

Autoheal tests nothing itself. It acts on Docker's unhealthy state, so a container without a healthcheck is never touched (README: "You must apply HEALTHCHECK to your docker images first"). How it works (Dockerfile reference, updated 2026-11-19):

  • Health starts as starting, a pass makes it healthy, retries failures in a row make it unhealthy, and one later pass heals it.
  • Exit code 0 is healthy, 1 unhealthy. A check slower than timeout fails. Failures in start_period are not counted.
Compose keyDefaultMeaning
interval30sWait between checks
timeout30sLongest time for one check
retries3Failures in a row until unhealthy
start_period0sGrace time for a slow start
start_interval5sCheck rhythm in that grace time (Docker Engine 25.0 or later)

Look at what a running container already has:

Linux#

Run in terminalbash
docker ps --format "table {{.Names}}\t{{.Status}}"
docker inspect --format '{{json .Config.Healthcheck}}' <your-container>
docker inspect --format '{{json .State.Health}}' <your-container>

Windows (PowerShell)#

Run in terminalpowershell
docker ps --format "table {{.Names}}\t{{.Status}}"
docker inspect --format '{{json .Config.Healthcheck}}' <your-container>
docker inspect --format '{{json .State.Health}}' <your-container>

Mac (Terminal)#

Same commands as Linux.

Check it worked. docker ps shows (healthy) or (unhealthy) in the status. null from the first inspect means no healthcheck. .State.Health holds the status and the output of recent checks (Docker keeps the first 4096 bytes).

No healthcheck yet? Add one to the Compose file. This one is for a web app with a health page on its internal port (dummy port and path):

File contentyaml
    healthcheck:
      test: ["CMD", "curl", "--fail", "--silent", "--max-time", "3", "http://127.0.0.1:8080/health"]
      interval: 30s
      timeout: 5s
      retries: 3
      start_period: 60s

Test the command by hand first: docker compose exec <service> curl --fail http://127.0.0.1:8080/health. If the image has no curl, the check fails every time and autoheal restarts a healthy app. Try wget -q --spider in slim images.

Tip: Check the app, not the internet. A probe that calls an outside website fails when your network does, and autoheal then restarts a container that did nothing wrong.

Step 2: Create the folder and pin the image#

Everything lives under ~/docker_volumes/autoheal. Autoheal stores no data, so we keep only config and backups. The README offers latest (rebuilt daily). The newest numbered tag, 1.2.0, is from July 2021 and lacks later features (see Settings). So we pin the digest of today's build, a fixed fingerprint of one exact image. latest appears here only to read it once.

Linux#

Run in terminalbash
mkdir -p ~/docker_volumes/autoheal/{config,backups}
cd ~/docker_volumes/autoheal
docker pull willfarrell/autoheal:latest
echo "AUTOHEAL_IMAGE=$(docker image inspect --format '{{index .RepoDigests 0}}' willfarrell/autoheal:latest)" > .env
chmod 600 .env
cat .env

Windows (PowerShell)#

Codepowershell
$base = "$HOME\docker_volumes\autoheal"
foreach ($d in "config","backups") { New-Item -ItemType Directory -Force "$base\$d" | Out-Null }
Set-Location $base
docker pull willfarrell/autoheal:latest
"AUTOHEAL_IMAGE=$(docker image inspect --format '{{index .RepoDigests 0}}' willfarrell/autoheal:latest)" | Set-Content -Encoding ascii .env
Get-Content .env

Mac (Terminal)#

Same commands as Linux.

Check it worked. One line of the shape AUTOHEAL_IMAGE=willfarrell/autoheal@sha256:<64 hex characters> (we did not run it, so we show no real value). If nothing follows the @, the pull failed: run it again.

Tip: Copy that line into your notes. We could not confirm how long Docker Hub keeps old daily builds pullable, so if a pinned digest stops pulling, read a new one and test again.

Step 3: Write the Compose file with a demo app#

One file holds autoheal and a harmless demo container we can break on purpose. The demo is healthy while the file /tmp/healthy exists.

Linux#

Run in terminalbash
cd ~/docker_volumes/autoheal
cat > compose.yaml << 'EOF'
services:
  autoheal:
    image: ${AUTOHEAL_IMAGE}
    container_name: autoheal
    restart: unless-stopped
    network_mode: none
    environment:
      AUTOHEAL_CONTAINER_LABEL: autoheal
      AUTOHEAL_INTERVAL: "10"
      AUTOHEAL_START_PERIOD: "30"
      AUTOHEAL_DEFAULT_STOP_TIMEOUT: "10"
      CURL_TIMEOUT: "30"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

  demo:
    image: busybox:1.38.0
    container_name: demo
    restart: unless-stopped
    command: ["sh", "-c", "touch /tmp/healthy && exec sleep 86400"]
    healthcheck:
      test: ["CMD", "test", "-f", "/tmp/healthy"]
      interval: 5s
      timeout: 3s
      retries: 2
      start_period: 5s
    labels:
      autoheal: "true"
      autoheal.stop.timeout: "2"
EOF

Windows (PowerShell)#

Codepowershell
Set-Location "$HOME\docker_volumes\autoheal"
@'
services:
  autoheal:
    image: ${AUTOHEAL_IMAGE}
    container_name: autoheal
    restart: unless-stopped
    network_mode: none
    environment:
      AUTOHEAL_CONTAINER_LABEL: autoheal
      AUTOHEAL_INTERVAL: "10"
      AUTOHEAL_START_PERIOD: "30"
      AUTOHEAL_DEFAULT_STOP_TIMEOUT: "10"
      CURL_TIMEOUT: "30"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

  demo:
    image: busybox:1.38.0
    container_name: demo
    restart: unless-stopped
    command: ["sh", "-c", "touch /tmp/healthy && exec sleep 86400"]
    healthcheck:
      test: ["CMD", "test", "-f", "/tmp/healthy"]
      interval: 5s
      timeout: 3s
      retries: 2
      start_period: 5s
    labels:
      autoheal: "true"
      autoheal.stop.timeout: "2"
'@ | Set-Content -Encoding ascii compose.yaml

Mac (Terminal)#

Same commands as Linux.

LineWhy
autoheal: "true"The label autoheal looks for. The quotes matter (Common mistakes)
AUTOHEAL_CONTAINER_LABELThe default, written out. It is a label name whose value must be true, not a container name
network_mode: noneThe README example does this. A local socket needs no network. Remove it for a webhook or a socket proxy
AUTOHEAL_INTERVAL, AUTOHEAL_START_PERIODCheck every 10 seconds. Wait 30 seconds once, when autoheal starts. Plain numbers, no s
autoheal.stop.timeoutPer-container wait before Docker kills it on restart. The demo's sleep ignores the stop signal, so we keep it short

On Docker Desktop the path /var/run/docker.sock is the documented socket for Mac and for Windows with WSL 2. We did not run it there.

Check it worked. docker compose config -q prints nothing when the file and .env are valid.

Step 4: Start it and read the log#

Linux#

Run in terminalbash
cd ~/docker_volumes/autoheal
docker compose up -d
docker compose ps
docker compose logs --tail=20 autoheal

Windows (PowerShell)#

Codepowershell
Set-Location "$HOME\docker_volumes\autoheal"
docker compose up -d
docker compose ps
docker compose logs --tail=20 autoheal

Mac (Terminal)#

Same commands as Linux.

We did not run this. From the script, the log shows the settings it read, then Monitoring containers for unhealthy status in 30 second(s). Healthy containers produce no lines: silence is normal.

Check it worked. docker compose ps shows autoheal running, and demo healthy after 5 to 10 seconds.

Step 5: Break the demo and watch it heal#

We delete the file the demo's healthcheck needs. The container keeps running, so Docker's restart policy stays idle. Only autoheal acts.

Linux#

Run in terminalbash
cd ~/docker_volumes/autoheal
docker compose exec demo rm /tmp/healthy
docker inspect --format '{{.State.Health.Status}}' demo
docker compose logs -f --tail=5 autoheal

Windows (PowerShell)#

Codepowershell
Set-Location "$HOME\docker_volumes\autoheal"
docker compose exec demo rm /tmp/healthy
docker inspect --format '{{.State.Health.Status}}' demo
docker compose logs -f --tail=5 autoheal

Mac (Terminal)#

Same commands as Linux.

Our estimate: two failed checks make demo unhealthy after 10 to 15 seconds, and the next 10-second pass restarts it. From the script the line looks like <dd-mm-yyyy hh:mm:ss> Container /demo (<12-character id>) found to be unhealthy - Restarting container now with 2s timeout. Its clock is UTC unless you mount /etc/localtime (README).

Check it worked. docker compose ps shows demo going starting, then healthy, with a fresh uptime: the start command recreates /tmp/healthy. Remove the demo afterwards: delete its block and run docker compose up -d --remove-orphans.

Tip: Run this break-it test only on a disposable container, never on a real database.

Step 6: Protect your own containers#

In the app's Compose file add the label and a healthcheck (Step 1), then recreate the container. Editing the file alone changes nothing.

File contentyaml
services:
  your-app:
    image: <your-image>:<pinned-tag>
    restart: unless-stopped
    labels:
      autoheal: "true"
      autoheal.stop.timeout: "30"
    healthcheck:
      test: ["CMD", "curl", "--fail", "--silent", "--max-time", "3", "http://127.0.0.1:8080/health"]
      interval: 30s
      timeout: 5s
      retries: 3
      start_period: 90s

Linux#

Run in terminalbash
cd <path-to-your-app>
docker compose up -d
docker inspect --format '{{json .Config.Labels}}' <your-container>

Windows (PowerShell)#

Codepowershell
Set-Location <path-to-your-app>
docker compose up -d
docker inspect --format '{{json .Config.Labels}}' <your-container>

Mac (Terminal)#

Same commands as Linux.

Check it worked. The labels show "autoheal":"true" in lower case. Autoheal sees every container on the host, so you never add the app to the autoheal file.

A program that saves data on exit needs an autoheal.stop.timeout above the default of 10 seconds. Time until a restart is roughly interval x retries, plus up to one AUTOHEAL_INTERVAL, plus the stop time (our reading, not a measurement).

Settings you can change#

From the script and the Dockerfile at commit f535158 (9 September 2025). Times are plain seconds.

VariableDefaultWhat it does
AUTOHEAL_CONTAINER_LABELautohealLabel name that must be true. all drops the label filter
AUTOHEAL_INTERVAL5Sleep between passes
AUTOHEAL_START_PERIOD0One wait when autoheal itself starts
AUTOHEAL_DEFAULT_STOP_TIMEOUT10Seconds before Docker kills a container on restart
AUTOHEAL_ONLY_MONITOR_RUNNINGfalseWhen true, ignores paused containers
DOCKER_SOCK/var/run/docker.sockSocket path, tcp://host:port, or tcps://host:port for TLS
CURL_TIMEOUT30Seconds curl waits for the Docker API
WEBHOOK_URLemptyGets a JSON message after each restart or failed restart
WEBHOOK_JSON_KEYcontentText field name in that JSON (Known bugs)
APPRISE_URLemptyGets title and body JSON after a restart
POST_RESTART_SCRIPTemptyA script inside the container, run after each attempt

The README lists the first eight. The last three exist in the script only. The old 1.2.0 image predates AUTOHEAL_ONLY_MONITOR_RUNNING, the notifications and plain-HTTP tcp://, so use a current digest for them. A webhook needs network access: remove network_mode: none.

In the Compose file use WEBHOOK_URL: ${AUTOHEAL_WEBHOOK}.

Tip: Treat the webhook URL as a secret. In .env write AUTOHEAL_WEBHOOK=https://hooks.example.com/<your-webhook-id> (a dummy value).

Restart loops: the danger of auto-healing#

The script has no restart limit, no growing delay and no memory. Each pass it restarts every unhealthy labelled container, skipping only those already restarting. A permanent fault therefore means restart, fail, restart, forever. A slow start is the usual cause:

Run in terminaltext
slow start -> check fails too soon -> unhealthy -> autoheal restarts -> slow start again

How to stay out of it:

  1. Give start_period more time than the slowest start, and retries of 3 or more.
  2. Do not let the probe depend on other services or the internet.
  3. Watch the log. The same name every few minutes is a loop. Pause with docker compose stop autoheal while you investigate.
  4. Leave databases unlabelled until you have watched a normal backup and crash recovery.

Two more traps. Autoheal can restart a container that Compose just stopped for up --force-recreate (issue 22, open since 2019). And a container you stopped by hand should stay stopped, because the list call returns running containers only (our reading of the script).

Run it with a socket proxy#

The socket gives autoheal root-level power over the host, and :ro on the mount does not limit the commands sent through it. The README supports a TCP address in DOCKER_SOCK, so autoheal can use a Docker socket proxy. It needs one read (list) and one write (restart), so the proxy needs CONTAINERS=1 and POST=1. The gain is smaller than for Traefik, which only reads; our sister guide explains what POST=1 opens.

File contentyaml
services:
  socket-proxy:
    image: tecnativa/docker-socket-proxy:3.4
    restart: unless-stopped
    environment:
      CONTAINERS: "1"
      POST: "1"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    networks:
      - autoheal-api

  autoheal:
    image: ${AUTOHEAL_IMAGE}
    restart: unless-stopped
    depends_on:
      - socket-proxy
    environment:
      DOCKER_SOCK: tcp://socket-proxy:2375
    networks:
      - autoheal-api

networks:
  autoheal-api:
    internal: true

We did not test this. Set DOCKER_SOCK: joining the network alone is not enough (issue 48). Never publish port 2375. Use a current digest: the July 2021 code (the 1.2.0 era) treats tcp:// as HTTPS with client certificates, the current script uses plain HTTP for tcp:// and HTTPS only for tcps://.

Put it behind HTTPS with Traefik? You do not need to#

Autoheal serves no web page and publishes no port, so there is nothing to put behind a proxy, at home or on a server with a domain.

With Traefik#

No labels or routes are needed. See our Traefik guide for apps that have a web page.

Without Traefik: Caddy#

No reverse_proxy line is needed for the same reason. Our Caddy guide covers apps that do.

Security and testing#

ControlHow
Docker socketTreat it as root access to the host. Keep autoheal on network_mode: none
Image ageAlpine 3.18 is end of life, and ARM builds trust a stale certificate list (issue 154), which matters most with a webhook. Scan your digest, for example with Trivy
Label choiceOpt in with autoheal=true. Avoid all: its exclusion label is broken (Known bugs)
SecretsA webhook URL in .env with chmod 600, never in Compose files or Git
ForksThe issues mention forks with extra features. We tested none. Read a fork's code before you give it the socket

Quick tests:

Run in terminalbash
cd ~/docker_volumes/autoheal
docker compose ps
docker compose logs --tail=50 autoheal
docker inspect --format '{{json .State.Health}}' demo

Alternatives#

OptionWhat it does
Compose restart:Restarts a container that exits, or after a daemon restart (Docker's docs). Not a health reaction
depends_on: condition: service_healthyWaits for a healthy dependency at start. Not continuous healing
deunhealthLabel deunhealth.restart.on.unhealthy=true, reads Docker events. MIT, last release v0.3.0 (October 2021), last commit 22 December 2025. Untested by us
Podman--health-on-failure=restart restarts without a watchdog; do not combine it with --restart (our Podman guide)

Common mistakes#

MistakeWhy it happensDo this instead
autoheal: true without quotes, nothing happens (issue 110: "No logs")YAML makes a boolean, Compose writes True, autoheal looks for true (issue 46)Write autoheal: "true" and read the labels with docker inspect
AUTOHEAL_CONTAINER_LABEL=jackett, a container name (issue 27)The variable holds a label nameKeep the default autoheal. The maintainer's answer: remove the variable
A healthcheck with a missing tool, or too strictSlim images have no curl, so every check failsRun the check by hand. Use start_period and retries of 3 or more
Rootless Docker with the system socket: autoheal exited with code 7 (issue 93)Rootless Docker has its own socketOne reporter mounted /run/user/$UID/docker.sock as /var/run/docker.sock. Not every exit 7 has this cause
all plus autoheal=false to exclude one app (issue 153)The script compares with "False": "no error or log line"Opt in with labels instead
A proxy network without DOCKER_SOCK: autoheal: not found (issue 48)Autoheal still looks for the local socketSet DOCKER_SOCK=tcp://<proxy>:2375
AI assistants: "restart: unless-stopped restarts unhealthy containers"Health state is mixed up with process exitRestart policies react to exit and daemon restart only. Use autoheal
AI assistants: invented options: a restart limit, backoff, autoheal.action, AUTOHEAL_EXCLUDEThey come from forks (one fork's pull request landed here by mistake: issue 149)Use only the variables in the Settings table
AI assistants: DOCKER_HOST, DOCKER_TLS_VERIFY, AUTOHEAL_INTERVAL: 30sThe README's TLS example sets Docker CLI variables, and Compose habits add unitsThe script reads only DOCKER_SOCK, and times are plain seconds

Tip: After adding the label, run docker compose up -d in the app's folder, then read its labels with docker inspect. Most "autoheal does nothing" cases are a label problem.

Tip: Fix the healthcheck first (start_period longer than a slow boot, retries at 3). Only then lower AUTOHEAL_INTERVAL: a fast poller on a sloppy check restarts too much.

Troubleshooting#

ProblemSolution
Nothing is restarteddocker inspect it: is it unhealthy, and is the label "autoheal":"true"?
Autoheal exits at startdocker compose logs autoheal: is the mounted socket path right?
Healthy app keeps restartingdocker inspect --format '{{json .State.Health}}' <name> shows the failing probe output
Docker Desktop is not runningStart it, then docker compose restart autoheal

Exact error texts#

  • unix socket is currently not available (exit code 1): the file at DOCKER_SOCK is not a socket. The text is from the script at commit f535158.
  • autoheal exited with code 7 (issue 93): a Raspberry Pi report. A 2026 comment fixed it with the rootless socket path.
  • <date> Restarting container <id> failed (issue 111): seen on recent builds while a manual curl -X POST to the same restart URL answers 204 No Content. No cause is confirmed. From the script, the line appears whenever the call fails or exceeds CURL_TIMEOUT.

Known bugs (open, December 2026)#

  • Issue 153: the autoheal=false exclusion in all mode matches only False.
  • Issue 152: the webhook key is content in the Dockerfile and text in the script. The Dockerfile wins. Set WEBHOOK_JSON_KEY yourself.
  • Issue 154 (Alpine update) and issue 147 (current numbered tags): no maintainer answer yet.
  • Issue 111: the restart failures above.

Updates and backups#

Autoheal has no data. Back up .env and compose.yaml.

Update. There is no release to follow. Check the commits and open issues, then read the digest again (Step 2) and recreate:

Run in terminalbash
cd ~/docker_volumes/autoheal
docker pull willfarrell/autoheal:latest
sed -i "s|^AUTOHEAL_IMAGE=.*|AUTOHEAL_IMAGE=$(docker image inspect --format '{{index .RepoDigests 0}}' willfarrell/autoheal:latest)|" .env
docker compose up -d

On a Mac use sed -i ''. On Windows edit the AUTOHEAL_IMAGE line by hand, then run docker compose up -d.

Linux and Mac#

Save as ~/docker_volumes/autoheal/backup.sh:

File contentbash
#!/usr/bin/env bash
set -euo pipefail
base="$HOME/docker_volumes/autoheal"
out="$base/backups/autoheal-$(date +%F).tar.gz"
tar -czf "$out" -C "$base" .env compose.yaml
chmod 600 "$out"

Run chmod 700 on it and add 0 3 * * * /home/<your-user>/docker_volumes/autoheal/backup.sh with crontab -e (Mac: /Users/...).

Windows (PowerShell)#

Save as $HOME\docker_volumes\autoheal\backup.ps1:

Codepowershell
$base = "$HOME\docker_volumes\autoheal"
$out = "$base\backups\autoheal-$(Get-Date -Format yyyy-MM-dd).tar.gz"
tar.exe -czf $out -C $base .env compose.yaml

In Task Scheduler run powershell.exe -NoProfile -File <full-path-to-the-script> daily at 03:00.

Restore test#

Unpack the archive in a spare folder and run docker compose config -q: no output means valid files. For a full test run docker compose up -d and repeat Step 5.

Performance and resources#

The README gives no figures and we measured none. Each pass makes one curl call and one jq run; the image is a few MB. Run docker stats autoheal to see your own numbers.

FAQ#

Does Docker restart unhealthy containers by itself? No. It sets the health state and sends an event. Restart policies react to exits and daemon restarts only. That gap is why this tool exists.

Will the project get updates? We cannot say. The last code change is from September 2025 and nobody has answered issue 156. Know the alternatives before you need them.

Sources#

Checked against the official docs on 2026-12-03. Nothing was run on a real machine by DIY Lab Hub; the commands come from the README, the script, the Docker documentation and the issues above.

Try one of these