Dorokhov.codes

05. Watchtower

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.