Sign inSign up

zachbg/auto-heal

By zachbg

•Updated 6 months ago

Automatically restart unhealthy Docker containers with webhook notifications

Image
1

1.6K

zachbg/auto-heal repository overview

⁠Auto-Heal

Automatically restart unhealthy Docker containers. When a container's healthcheck fails, auto-heal restarts it — no manual intervention needed.

⁠Why?

Docker detects unhealthy containers but does nothing about it. Your database hangs, your API deadlocks, your cache runs out of memory — Docker just marks it "unhealthy" and walks away. Auto-heal fixes that.

⁠Quick Start

services:
  auto-heal:
    image: zachbg/auto-heal:latest
    restart: always
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
    environment:
      AUTOHEAL_CONTAINER_LABEL: all  # or label specific containers

  # Example: this container will be auto-healed
  webapp:
    image: nginx
    labels:
      autoheal: "true"
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost"]
      interval: 30s
      timeout: 5s
      retries: 3

⁠Environment Variables

VariableDefaultDescription
AUTOHEAL_CONTAINER_LABELautohealLabel to filter containers. Set to all to heal everything
AUTOHEAL_INTERVAL5Seconds between health checks
AUTOHEAL_START_PERIOD0Seconds to wait before starting
AUTOHEAL_DEFAULT_STOP_TIMEOUT10Graceful stop timeout per restart
AUTOHEAL_WEBHOOK_URLNotification webhook URL
AUTOHEAL_WEBHOOK_TYPEgenericdiscord, slack, or generic
AUTOHEAL_LOG_ALLfalseLog all container statuses each cycle

⁠Container Labels

LabelDescription
autoheal=trueEnable auto-healing for this container
autoheal.stop.timeout=30Override stop timeout for this container

⁠Examples

⁠Heal all containers with healthchecks
environment:
  AUTOHEAL_CONTAINER_LABEL: all
⁠Heal only labeled containers + Discord alerts
environment:
  AUTOHEAL_CONTAINER_LABEL: autoheal
  AUTOHEAL_WEBHOOK_URL: https://discord.com/api/webhooks/xxx/yyy
  AUTOHEAL_WEBHOOK_TYPE: discord
⁠Conservative healing (longer intervals)
environment:
  AUTOHEAL_INTERVAL: 30
  AUTOHEAL_DEFAULT_STOP_TIMEOUT: 30
  AUTOHEAL_START_PERIOD: 60

Tag summary

Content type

Image

Digest

sha256:eb3a5ddb5…

Size

16.7 MB

Last updated

6 months ago

docker pull zachbg/auto-heal