Author: Matthew GriffinLast Updated: Fri, Feb 25, 2022
This tutorial explains how to install Watchtower on Ubuntu 20.04.
Watchtower will automatically keep all of your running Docker containers up to date. This can be useful if you run all of your self-hosted services or apps with Docker. Every few minutes, Watchtower will pull the latest image for your application and compare it to the one used to run the container. Suppose there are any changes to the image. In that case, Watchtower will automatically restart the container using the new image, and the same
docker run or
docker-compose configuration initially used to start it.
Before you begin, you should:
Log in to your server as a non-root user.
Ideally, you should already have Docker installed on your server, as you should already be using it. If you don't, you can install it by following these steps:
Remove any older versions of Docker and the Docker engine.
$ sudo apt remove docker docker-engine docker.io containerd runc
Install Docker using
$ sudo snap install docker
If you don't have a Docker container running, create one. As an example, you can use the Docker
$ sudo docker run -d -p 80:80 docker/getting-started
To check if you have any existing running containers, you can run
Create the Watchtower Docker container.
$ sudo docker run --detach \ --name watchtower \ --volume /var/run/docker.sock:/var/run/docker.sock \ containrrr/watchtower
Check that Watchtower is running by using
docker. The status should be
$ sudo docker ps STATUS Up x seconds/minutes
You have now successfully installed and configured Watchtower to update your Docker container images regularly.
Watchtower has some additional configurations that can be changed using command line arguments.
You can set the timezone that Watchtower uses by mounting your host machine's
/etc/localtime file into the container.
$ sudo docker run --detach \ --name watchtower \ --volume /var/run/docker.sock:/var/run/docker.sock \ --volume /etc/localtime:/etc/localtime:ro \ containrrr/watchtower
By default, Watchtower does not remove old images. Enabling this may be useful if you need to save disk space.
$ sudo docker run --detach \ --name watchtower \ --volume /var/run/docker.sock:/var/run/docker.sock \ --volume /etc/localtime:/etc/localtime:ro \ containrrr/watchtower \ --cleanup
More Watchtower configuration options can be found in the documentation below.