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.

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.
| What | Value (official sources, read 3 December 2026) |
|---|---|
| Project | willfarrell/docker-autoheal, licence MIT (copyright 2018) |
| Releases | No GitHub release. The newest git tag is v0.7.0 |
| Docker Hub tags | 1.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 change | Merged 9 September 2025 (a shellcheck clean-up) |
| Image to pin | The digest of the current build (Step 2) |
| Time needed | About 25 minutes (our estimate) |
| Ports | None |
| Official docs | The 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,
curlandjq. 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.
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-meorhooks.example.com). Replace it with your own and keep real secrets out of Git.
| System | What to have |
|---|---|
| Linux | Docker Engine and the Compose plugin |
| Windows | Windows 10 or later, Docker Desktop (WSL 2, Linux containers), PowerShell |
| Mac | Docker Desktop, Intel or Apple Silicon |
docker --version docker compose version
- [ ] Both commands print a version
- [ ] The container you want to protect is not a database, and its image has
curlorwget - [ ] 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 ithealthy,retriesfailures in a row make itunhealthy, and one later pass heals it. - Exit code
0is healthy,1unhealthy. A check slower thantimeoutfails. Failures instart_periodare not counted.
| Compose key | Default | Meaning |
|---|---|---|
interval | 30s | Wait between checks |
timeout | 30s | Longest time for one check |
retries | 3 | Failures in a row until unhealthy |
start_period | 0s | Grace time for a slow start |
start_interval | 5s | Check rhythm in that grace time (Docker Engine 25.0 or later) |
Look at what a running container already has:
Linux#
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)#
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):
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#
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)#
$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#
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)#
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.
| Line | Why |
|---|---|
autoheal: "true" | The label autoheal looks for. The quotes matter (Common mistakes) |
AUTOHEAL_CONTAINER_LABEL | The default, written out. It is a label name whose value must be true, not a container name |
network_mode: none | The README example does this. A local socket needs no network. Remove it for a webhook or a socket proxy |
AUTOHEAL_INTERVAL, AUTOHEAL_START_PERIOD | Check every 10 seconds. Wait 30 seconds once, when autoheal starts. Plain numbers, no s |
autoheal.stop.timeout | Per-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#
cd ~/docker_volumes/autoheal docker compose up -d docker compose ps docker compose logs --tail=20 autoheal
Windows (PowerShell)#
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#
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)#
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.
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#
cd <path-to-your-app>
docker compose up -d
docker inspect --format '{{json .Config.Labels}}' <your-container>
Windows (PowerShell)#
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.
| Variable | Default | What it does |
|---|---|---|
AUTOHEAL_CONTAINER_LABEL | autoheal | Label name that must be true. all drops the label filter |
AUTOHEAL_INTERVAL | 5 | Sleep between passes |
AUTOHEAL_START_PERIOD | 0 | One wait when autoheal itself starts |
AUTOHEAL_DEFAULT_STOP_TIMEOUT | 10 | Seconds before Docker kills a container on restart |
AUTOHEAL_ONLY_MONITOR_RUNNING | false | When true, ignores paused containers |
DOCKER_SOCK | /var/run/docker.sock | Socket path, tcp://host:port, or tcps://host:port for TLS |
CURL_TIMEOUT | 30 | Seconds curl waits for the Docker API |
WEBHOOK_URL | empty | Gets a JSON message after each restart or failed restart |
WEBHOOK_JSON_KEY | content | Text field name in that JSON (Known bugs) |
APPRISE_URL | empty | Gets title and body JSON after a restart |
POST_RESTART_SCRIPT | empty | A 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
.envwriteAUTOHEAL_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:
slow start -> check fails too soon -> unhealthy -> autoheal restarts -> slow start again
How to stay out of it:
- Give
start_periodmore time than the slowest start, andretriesof 3 or more. - Do not let the probe depend on other services or the internet.
- Watch the log. The same name every few minutes is a loop. Pause with
docker compose stop autohealwhile you investigate. - 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.
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#
| Control | How |
|---|---|
| Docker socket | Treat it as root access to the host. Keep autoheal on network_mode: none |
| Image age | Alpine 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 choice | Opt in with autoheal=true. Avoid all: its exclusion label is broken (Known bugs) |
| Secrets | A webhook URL in .env with chmod 600, never in Compose files or Git |
| Forks | The issues mention forks with extra features. We tested none. Read a fork's code before you give it the socket |
Quick tests:
cd ~/docker_volumes/autoheal
docker compose ps
docker compose logs --tail=50 autoheal
docker inspect --format '{{json .State.Health}}' demo
Alternatives#
| Option | What 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_healthy | Waits for a healthy dependency at start. Not continuous healing |
| deunhealth | Label 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#
| Mistake | Why it happens | Do 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 name | Keep the default autoheal. The maintainer's answer: remove the variable |
| A healthcheck with a missing tool, or too strict | Slim images have no curl, so every check fails | Run 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 socket | One 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 socket | Set DOCKER_SOCK=tcp://<proxy>:2375 |
AI assistants: "restart: unless-stopped restarts unhealthy containers" | Health state is mixed up with process exit | Restart policies react to exit and daemon restart only. Use autoheal |
AI assistants: invented options: a restart limit, backoff, autoheal.action, AUTOHEAL_EXCLUDE | They 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: 30s | The README's TLS example sets Docker CLI variables, and Compose habits add units | The script reads only DOCKER_SOCK, and times are plain seconds |
Tip: After adding the label, run
docker compose up -din the app's folder, then read its labels withdocker inspect. Most "autoheal does nothing" cases are a label problem.
Tip: Fix the healthcheck first (
start_periodlonger than a slow boot,retriesat 3). Only then lowerAUTOHEAL_INTERVAL: a fast poller on a sloppy check restarts too much.
Troubleshooting#
| Problem | Solution |
|---|---|
| Nothing is restarted | docker inspect it: is it unhealthy, and is the label "autoheal":"true"? |
| Autoheal exits at start | docker compose logs autoheal: is the mounted socket path right? |
| Healthy app keeps restarting | docker inspect --format '{{json .State.Health}}' <name> shows the failing probe output |
| Docker Desktop is not running | Start it, then docker compose restart autoheal |
Exact error texts#
unix socket is currently not available(exit code 1): the file atDOCKER_SOCKis not a socket. The text is from the script at commitf535158.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 manualcurl -X POSTto the same restart URL answers204 No Content. No cause is confirmed. From the script, the line appears whenever the call fails or exceedsCURL_TIMEOUT.
Known bugs (open, December 2026)#
- Issue 153: the
autoheal=falseexclusion inallmode matches onlyFalse. - Issue 152: the webhook key is
contentin the Dockerfile andtextin the script. The Dockerfile wins. SetWEBHOOK_JSON_KEYyourself. - 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:
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:
#!/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:
$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#
- docker-autoheal repository and README, the script, Dockerfile and LICENSE (MIT) at commit
f535158(9 September 2025) - Docker Hub tags of willfarrell/autoheal (API read 3 December 2026)
- Docker docs: Dockerfile HEALTHCHECK (19 November 2026), Compose healthcheck and startup order (20 November 2026), restart policies (16 August 2026), Docker Desktop FAQ (3 November 2026)
- Tecnativa/docker-socket-proxy README, deunhealth README and Podman health-on-failure
- Issues read: 22, 27, 46, 48, 93, 110, 111, 147, 149, 150, 152, 153, 154, 156
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.