arrow_back
Back

Watchtower: automatic Docker image updates for running containers

Andrew Dorokhov Andrew Dorokhov schedule 1 min read
menu_book Table of Contents

There’s an interesting image called containrrr/watchtower that is used for automating the process of updating Docker containers.

docker-compose.yml:

version: "2"
services:
  watchtower:
    container_name: watchtower
    image: containrrr/watchtower
    command: --interval 60
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /home/andrew/.docker/config.json:/config.json

When using private images on Docker Hub, the containers being watched needs to use the full image name, including the repository prefix index.docker.io.

// instead of:
myuser/myimage

// use: 
index.docker.io/myuser/myimage

Also, after such changes we need to recreate the containers.

Custom containers

If we want to be updating only specific containers instead of all of them, we should specify them like this:

version: "2"
services:
  watchtower:
    container_name: watchtower
    image: containrrr/watchtower
    command: --cleanup --interval 60 dorokhov.dev.app dorokhov.codes.app
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /home/andrew/.docker/config.json:/config.json

Options

Flag --cleanup removes old images after updating.

When this flag is specified, watchtower will remove the old image after restarting a container with a new image.

Use this option to prevent the accumulation of orphaned images on your system as containers are updated.

code

Need Help with Development?

Happy to help — reach out via the contacts or go straight to my Upwork profile.

work View Upwork Profile arrow_forward
Next Article

Docker GUI applications: X11, display forwarding, and desktop apps

arrow_forward