There’s an interesting image called containrrr/watchtower that
is used for automating the process of updating Docker containers.
When an image is updated in the registry, Watchtower pulls the new image and restarts the container.
docker-compose.yml:
version: "2"
services:
watchtower:
container_name: watchtower
image: containrrr/watchtower
restart: always
command: --interval 60
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /home/andrew/.docker/config.json:/config.json
Standalone run:
docker run -d --name watchtower \
--restart always \
-v /var/run/docker.sock:/var/run/docker.sock \
containrrr/watchtower --interval 60
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.
Andrew Dorokhov