Convert Figma logo to code with AI

willfarrell logodocker-autoheal

Monitor and restart unhealthy docker containers.

1,293
225
1,293
55

Top Related Projects

19,215

Slim(toolkit): Don't change anything in your container image and minify it by up to 30x (and for compiled languages even more) making it secure too! (free and open source)

A process for automating Docker container base image updates.

Automatically update running docker containers with newest available image

2,700

An open-source, next-generation "runc" that empowers rootless containers to run workloads such as Systemd, Docker, Kubernetes, just like VMs.

Quick Overview

The willfarrell/docker-autoheal repository is a Docker container that automatically detects and restarts unhealthy Docker containers. It monitors the health status of other containers and takes action when they become unhealthy, helping to maintain the overall stability of a Docker-based system.

Pros

  • Improves system reliability by automatically restarting unhealthy containers
  • Easy to set up and integrate into existing Docker environments
  • Lightweight and consumes minimal resources
  • Customizable through environment variables

Cons

  • Requires containers to have health checks configured
  • May mask underlying issues by restarting containers without addressing root causes
  • Limited to Docker environments and not applicable to other container runtimes
  • Potential for cascading restarts if not configured properly

Getting Started

To use the docker-autoheal container, follow these steps:

  1. Pull the docker-autoheal image:
docker pull willfarrell/autoheal
  1. Run the container with the following command:
docker run -d \
    --name autoheal \
    --restart=always \
    -e AUTOHEAL_CONTAINER_LABEL=all \
    -v /var/run/docker.sock:/var/run/docker.sock \
    willfarrell/autoheal
  1. Ensure your other containers have health checks configured and the autoheal=true label:
version: '3'
services:
  my_app:
    image: my_app_image
    labels:
      - "autoheal=true"
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost"]
      interval: 30s
      timeout: 10s
      retries: 3

With these steps, the autoheal container will monitor and restart unhealthy containers in your Docker environment.

Competitor Comparisons

19,215

Slim(toolkit): Don't change anything in your container image and minify it by up to 30x (and for compiled languages even more) making it secure too! (free and open source)

Pros of Slim

  • Focuses on reducing Docker image size, potentially improving deployment speed and resource usage
  • Offers a more comprehensive toolset for image analysis and optimization
  • Provides a CLI tool for easier integration into development workflows

Cons of Slim

  • More complex to set up and use compared to the simpler autoheal functionality
  • May require more configuration and fine-tuning to achieve optimal results
  • Not specifically designed for container health monitoring and automatic restarts

Code Comparison

Slim example (analyzing a Docker image):

slim build --target my-image:latest --http-probe

Docker-autoheal example (in docker-compose.yml):

services:
  autoheal:
    image: willfarrell/autoheal
    environment:
      - AUTOHEAL_CONTAINER_LABEL=all
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

Summary

Slim is a powerful tool for optimizing Docker images, offering extensive analysis and size reduction capabilities. It's more complex but provides greater control over image optimization. Docker-autoheal, on the other hand, is a simpler solution focused specifically on monitoring container health and performing automatic restarts when needed. The choice between the two depends on whether the primary goal is image optimization (Slim) or container health management (Docker-autoheal).

A process for automating Docker container base image updates.

Pros of Watchtower

  • Automatically updates Docker containers to the latest available image
  • Supports multiple update policies (e.g., always, on schedule)
  • Can notify users about updates via various notification channels

Cons of Watchtower

  • Lacks specific container health monitoring features
  • May not be suitable for environments requiring strict version control
  • Doesn't offer granular control over individual container restart policies

Code Comparison

Autoheal:

docker run -d \
    --name autoheal \
    --restart=always \
    -e AUTOHEAL_CONTAINER_LABEL=all \
    -v /var/run/docker.sock:/var/run/docker.sock \
    willfarrell/autoheal

Watchtower:

docker run -d \
    --name watchtower \
    -v /var/run/docker.sock:/var/run/docker.sock \
    containrrr/watchtower

Summary

Autoheal focuses on monitoring and restarting unhealthy containers, while Watchtower emphasizes keeping containers updated with the latest images. Autoheal is better suited for maintaining container health in production environments, whereas Watchtower excels in development or staging environments where frequent updates are desired. The choice between the two depends on specific use cases and requirements for container management and maintenance.

Automatically update running docker containers with newest available image

Pros of Ouroboros

  • Automatically updates containers to their latest versions
  • Supports multiple container orchestration platforms (Docker, Kubernetes)
  • Offers more customization options and flexibility

Cons of Ouroboros

  • More complex setup and configuration
  • Potentially higher resource usage due to additional features

Code Comparison

Autoheal:

docker run -d \
    --name autoheal \
    --restart=always \
    -e AUTOHEAL_CONTAINER_LABEL=all \
    -v /var/run/docker.sock:/var/run/docker.sock \
    willfarrell/autoheal

Ouroboros:

docker run -d \
    --name ouroboros \
    -v /var/run/docker.sock:/var/run/docker.sock \
    pyouroboros/ouroboros

Key Differences

  1. Functionality:

    • Autoheal focuses on restarting unhealthy containers
    • Ouroboros updates containers to their latest versions
  2. Scope:

    • Autoheal is primarily for Docker environments
    • Ouroboros supports multiple container platforms
  3. Complexity:

    • Autoheal is simpler to set up and use
    • Ouroboros offers more features but requires more configuration
  4. Resource Usage:

    • Autoheal is generally lighter on system resources
    • Ouroboros may consume more resources due to its broader functionality
  5. Customization:

    • Autoheal has limited customization options
    • Ouroboros provides more flexibility in terms of update schedules and container selection
2,700

An open-source, next-generation "runc" that empowers rootless containers to run workloads such as Systemd, Docker, Kubernetes, just like VMs.

Pros of Sysbox

  • Provides stronger isolation and security for containers by creating system containers
  • Enables running Docker and Kubernetes inside containers, allowing for nested containerization
  • Supports a wider range of use cases, including running systemd, Docker, and Kubernetes inside containers

Cons of Sysbox

  • More complex setup and configuration compared to Docker Autoheal
  • Requires specific kernel features and may not be compatible with all systems
  • Higher resource overhead due to the creation of system containers

Code Comparison

Docker Autoheal:

HEALTHCHECK --interval=5s --timeout=3s --retries=3 \
  CMD curl -f http://localhost/ || exit 1

Sysbox:

docker run --runtime=sysbox-runc -it --rm \
  --name=syscont nestybox/ubuntu-bionic-systemd-docker

Summary

Docker Autoheal is a lightweight solution focused on automatically restarting unhealthy containers, while Sysbox is a more comprehensive container runtime that provides enhanced isolation and functionality. Sysbox offers greater flexibility and security but comes with increased complexity and resource requirements. The choice between the two depends on specific use cases and infrastructure needs.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Docker Autoheal

Monitor and restart unhealthy docker containers. This functionality was proposed to be included with the addition of HEALTHCHECK, however didn't make the cut. This container is a stand-in till there is native support for --exit-on-unhealthy https://github.com/docker/docker/pull/22719.

Supported tags and Dockerfile links

How to use

1. Docker CLI

UNIX socket passthrough

docker run -d \
    --name autoheal \
    --restart=always \
    -e AUTOHEAL_CONTAINER_LABEL=all \
    -v /var/run/docker.sock:/var/run/docker.sock \
    willfarrell/autoheal

TCP socket

docker run -d \
    --name autoheal \
    --restart=always \
    -e AUTOHEAL_CONTAINER_LABEL=all \
    -e DOCKER_SOCK=tcp://$HOST:$PORT \
    -v /path/to/certs/:/certs/:ro \
    willfarrell/autoheal

TCP with mTLS (HTTPS)

docker run -d \
    --name autoheal \
    --restart=always \
    --tlscacert=/certs/ca.pem \
    --tlscert=/certs/client-cert.pem \
    --tlskey=/certs/client-key.pem \
    -e AUTOHEAL_CONTAINER_LABEL=all \
    -e DOCKER_HOST=tcp://$HOST:2376 \
    -e DOCKER_SOCK=tcps://$HOST:2376 \
    -e DOCKER_TLS_VERIFY=1 \
    -v /path/to/certs/:/certs/:ro \
    willfarrell/autoheal

The certificates and keys need these names and resides under /certs inside the container:

  • ca.pem
  • client-cert.pem
  • client-key.pem

See https://docs.docker.com/engine/security/https/ for how to configure TCP with mTLS

Change Timezone

If you need the timezone to match the local machine, you can map the /etc/localtime into the container.

docker run ... -v /etc/localtime:/etc/localtime:ro

2. Use in your container image

Choose one of the three alternatives:

a) Apply the label autoheal=true to your container to have it watched;
b) Set ENV AUTOHEAL_CONTAINER_LABEL=all to watch all running containers;
c) Set ENV AUTOHEAL_CONTAINER_LABEL to existing container label that has the value true;

Note: You must apply HEALTHCHECK to your docker images first.
See https://docs.docker.com/engine/reference/builder/#healthcheck for details.

Docker Compose (example)

services:
  app:
    extends:
      file: ${PWD}/services.yml
      service: app
    labels:
      autoheal-app: true

  autoheal:
    deploy:
      replicas: 1
    environment:
      AUTOHEAL_CONTAINER_LABEL: autoheal-app
    image: willfarrell/autoheal:latest
    network_mode: none
    restart: always
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /var/run/docker.sock:/var/run/docker.sock

Optional Container Labels

autoheal.stop.timeout=20Per containers override for stop timeout seconds during restart

Environment Defaults

VariableDescription
AUTOHEAL_CONTAINER_LABEL=autohealset to existing label name that has the value true
AUTOHEAL_INTERVAL=5check every 5 seconds
AUTOHEAL_START_PERIOD=0wait 0 seconds before first health check
AUTOHEAL_DEFAULT_STOP_TIMEOUT=10Docker waits max 10 seconds (the Docker default) for a container to stop before killing during restarts (container overridable via label, see below)
AUTOHEAL_ONLY_MONITOR_RUNNING=falseAll containers monitored by default. Set this to true to only monitor running containers. This will result in Paused contaners being ignored.
DOCKER_SOCK=/var/run/docker.sockUnix socket for curl requests to Docker API
CURL_TIMEOUT=30--max-time seconds for curl requests to Docker API
WEBHOOK_URL=""post message to the webhook if a container was restarted (or restart failed)

Testing (building locally)

docker buildx build -t autoheal .

docker run -d \
    -e AUTOHEAL_CONTAINER_LABEL=all \
    -v /var/run/docker.sock:/var/run/docker.sock \
    autoheal