cascandaliato / docker-restarter

MIT License
12 stars 0 forks source link

docker-restarter 🐋♻️

Sample usage

docker-compose.yml

services:
  restarter:
    image: ghcr.io/cascandaliato/docker-restarter
    container_name: restarter
    init: true
    # environment:
    #   RESTARTER_CHECK_EVERY_SECONDS: 60
    #   RESTARTER_GC_EVERY_SECONDS: 300
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro

  # will restart every two minutes
  vpn:
    image: alpine
    container_name: vpn
    command: sleep 120
    init: true
    restart: always

  torrent:
    container_name: torrent
    image: alpine
    init: true
    command: sh -c 'apk add curl; sleep infinite'
    network_mode: &vpn_network service:vpn
    labels:
      restarter.network_mode: *vpn_network
    healthcheck:
      test: "curl -sf http://ipinfo.io/ip  || exit 1"
      interval: 10s
      start_period: 1s

In the example above, docker-restarter will restart containers vpn and torrent in the following cases:

These settings can be set at global level via similarly named environment variables:

Note: all values are case-insensitive.