version: '3.9'
services:
autoheal:
image: willfarrell/autoheal
container_name: autoheal
restart: always
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /etc/localtime:/etc/localtime:ro
environment:
- AUTOHEAL_CONTAINER_LABEL=autoheal
- AUTOHEAL_INTERVAL=300 # check every 300 seconds
- AUTOHEAL_START_PERIOD=10 # wait 10 seconds before first health check
networks:
- traefik-network
networks:
traefik-network:
external: true
Pour que Autoheal puisse redémarrer les conteneurs qui ont un statut “unhealthy” il faudra par la suite leur ajouter le label suivant :
labels:
- autoheal=true
Mais également configuré un Healthcheck sur les images qui n'en n'ont pas par défaut.
healthcheck:
test: ["CMD-SHELL", "pg_isready -U $DB_USER"]
interval: 10s
timeout: 5s
retries: 5
healthcheck:
test: curl --fail http://localhost:80 || exit 1
interval: 1m
timeout: 30s
retries: 3
healthcheck:
test: wget -nv -t1 --spider 'http://localhost:80'
interval: 1m
timeout: 30s
retries: 3
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
timeout: 20s
retries: 10
healthcheck:
test: ["CMD", "bash", "-c", "exec 5<>/dev/tcp/127.0.0.1/8000"]
interval: 5s
timeout: 5s
retries: 3
healthcheck:
test: ["CMD-SHELL", "apt-get update -y && apt-get install -y curl && curl --fail http://localhost:8000 || exit 1"]
interval: 5s
timeout: 3s
retries: 5