Files
Compose-Files/Backups/Miker/.trash/Watchtower 2.md
T
2026-07-20 09:23:17 -04:00

5.2 KiB
Raw Blame History

Watchtower Service Documentation

Overview

Watchtower is a lightweight and powerful tool designed to automate the process of keeping Docker containers up-to-date. By monitoring the Docker socket, Watchtower checks for updates to container images, pulls the latest versions, and restarts the containers with minimal intervention. This automation is especially useful in home lab environments or production setups, reducing the need for manual updates and ensuring containers remain secure and current.


Key Features

  1. Automated Updates: Automatically checks for and applies updates to running containers.
  2. Scheduled Checks: Allows for configurable schedules to avoid disruption during peak usage times.
  3. Resource Optimization: Cleans up outdated images after updates to conserve disk space.
  4. Ease of Use: Minimal setup and configuration required for seamless integration with Docker.

Docker Compose Configuration

Heres the docker-compose.yml file for deploying Watchtower:

services:

watchtower:

image: containrrr/watchtower
container_name: 'watchtower'
restart: 'unless-stopped'
environment:
	TZ: America/New_York
	WATCHTOWER_CLEANUP: true
	WATCHTOWER_INCLUDE_RESTARTING: true
	WATCHTOWER_ROLLING_RESTARTING: true
	WATCHTOWER_SCHEDULE: "0 0 4 * * *"
	WATCHTOWER_INCLUDE_STOPPED: true
	WATCHTOWER_NOTIFICATIONS: email
	WATCHTOWER_NOTIFICATIONS_HOSTNAME: "Docker Server"
	WATCHTOWER_NOTIFICATION_EMAIL_FROM: miker@mmcfetridge.net
	WATCHTOWER_NOTIFICATION_EMAIL_TO: miker@mmcfetridge.net
	WATCHTOWER_NOTIFICATION_EMAIL_SERVER: mail.mmcfetridge.net
	WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PORT: 587
	WATCHTOWER_NOTIFICATION_EMAIL_SERVER_USER: miker@mmcfetridge.net
	WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PASSWORD: "password"
security_opt:
- no-new-privileges:true
volumes:
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
- /var/run/docker.sock:/var/run/docker.sock
- command: --cleanup --schedule "0 3 * * *"

Configuration Explanation

  1. Image:
    The containrrr/watchtower image is the official Watchtower image, ensuring reliability and access to the latest features.

  2. Container Name:
    Naming the container watchtower simplifies management and identification in your Docker environment.

  3. Restart Policy:
    The restart: unless-stopped policy ensures that Watchtower stays active and restarts automatically after reboots or crashes.

  4. Volumes:

    • /var/run/docker.sock: Provides Watchtower access to Docker's API, enabling it to monitor and manage other containers.
  5. Command:

    • --cleanup: Automatically removes outdated images after successful updates to save storage space.
    • --schedule "0 3 * * *": Configures Watchtower to check for updates daily at 3:00 AM UTC, a time chosen to minimize impact on regular operations.

Deployment Instructions

  1. Save the Configuration:
    Save the provided docker-compose.yml file to a directory of your choice.

  2. Deploy the Service:
    Start the Watchtower service with the following command:

    docker-compose up -d
    
  3. Verify the Deployment:
    Check that Watchtower is running:

    docker ps
    
  4. Monitor Logs:
    Review the logs to ensure that Watchtower is functioning as expected:

    docker logs watchtower
    

Security Considerations

  • Docker Socket Access:
    The Docker socket grants full access to the Docker API. Restrict access to the Docker host to trusted users and monitor logs for unusual activity.

  • Backup Before Updates:
    While Watchtower is reliable, always maintain backups of critical containers and data to mitigate risks associated with updates.

  • Testing in Staging:
    If possible, test updates in a staging environment before applying them to production systems.


Benefits of Using Watchtower

  • Efficiency: Automates repetitive update tasks, saving time and effort.
  • Reliability: Ensures containers are consistently running the latest and most secure versions.
  • Resource Optimization: Prevents outdated images from consuming unnecessary storage space.
  • Convenience: Minimal configuration required for ongoing maintenance of your Docker environment.

Advanced Options

  • Excluding Containers:
    You can exclude specific containers from being updated by adding the com.centurylinklabs.watchtower.enable label set to false in their configurations:

    labels:
      - "com.centurylinklabs.watchtower.enable=false"
    
  • Notification Integrations:
    Configure Watchtower to send update notifications to services like Slack, email, or webhooks for better monitoring:

    environment:
      WATCHTOWER_NOTIFICATIONS: "slack"
      WATCHTOWER_NOTIFICATION_SLACK_HOOK_URL: "<your-slack-webhook-url>"
    

By integrating Watchtower into your home lab or production environment, you can maintain an up-to-date and secure container ecosystem with minimal manual intervention. Its a set-it-and-forget-it tool that streamlines container management, allowing you to focus on other aspects of your infrastructure.