This Docker image is designed to automatically restart specified Docker containers and send notifications to a Discord channel or/and Slack channel upon each restart. It's particularly useful for maintaining long-running services, ensuring they're periodically refreshed and stakeholders are informed of these actions.
- Automated Container Restart: Restart specified Docker containers.
- (optional) Discord Notifications: Sends a message to a Discord channel after each container restart.
- (optional) Slack Notifications: Sends a message to a Slack channel after each container restart.
- Support for Docker Socket Proxy for enhanced security
- Configurable execution timing and intervals
TBA
TBA
Variable | Description | Default |
---|---|---|
DISCORD_WEBHOOK_URL |
Discord webhook URL for notifications | - |
SLACK_WEBHOOK_URL |
Slack webhook URL for notifications | - |
RESTART_CONTAINERS |
Comma-separated list of container names to restart | - |
RUN_ON_STARTUP |
Whether to run on container startup | false |
CRON_SCHEDULE |
Cron expression for scheduling restarts | 0 4 * * FRI |
CYCLE_PERIOD |
Time between container restarts (ms) | 10000 |
DOCKER_HOST |
Docker daemon connection URL (optional) | - |
The application supports two ways to connect to the Docker daemon:
-
Direct Socket Access (Default)
- Uses the Docker socket at
/var/run/docker.sock
- Requires mounting the socket in the container
- Example Docker Compose configuration:
volumes: - /var/run/docker.sock:/var/run/docker.sock
- Uses the Docker socket at
-
Docker Socket Proxy (Optional)
- Uses a secure proxy to access the Docker API
- Requires the Docker Socket Proxy service
- Example Docker Compose configuration:
environment: DOCKER_HOST: 'tcp://docker-socket-proxy:2375' networks: - docker-socket-proxy
Run the container with the following command:
docker run -d \
-e CRON_SCHEDULE="0 4 * * FRI" \
-e RESTART_CONTAINERS="container1,container2" \
-e DISCORD_WEBHOOK_URL="your_discord_webhook_url" \
-e SLACK_WEBHOOK_URL="your_slack_webhook_url" \
-v /var/run/docker.sock:/var/run/docker.sock \
index.docker.io/deduard/tools:restart-notifier-latest
services:
restart-notifier:
container_name: restart-notifier
image: index.docker.io/deduard/tools:restart-notifier-latest
restart: unless-stopped
environment:
DISCORD_WEBHOOK_URL: 'https://discord.com/api/webhooks/119207436456853270/mRC3HfPoT5_MFsvn3sHUuG1Qeeg3WTUAo_bf0LR8'
SLACK_WEBHOOK_URL: 'https://hooks.slack.com/services/T04JS2CSY4U/B06HRRFSRGW/1UL9bv1i1JnaYsUBo'
RESTART_CONTAINERS: "nervous_moore1,nervous_moore2"
RUN_ON_STARTUP: "false"
CRON_SCHEDULE: "0 4 * * FRI" # Every Friday at 4:00 AM
CYCLE_PERIOD: "10000" # 10 sec
volumes:
- /var/run/docker.sock:/var/run/docker.sock