
Introduction
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.
Prerequisites
Before you begin, you should:
- Deploy an Ubuntu 20.04 server.
- Update the server.
- Create a non-root user with sudo privileges.
- Log in to your server as a non-root user.
Installation
Docker
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 runcInstall Docker using
snap.$ sudo snap install docker
Docker Container
If you don't have a Docker container running, create one. As an example, you can use the Docker
getting-startedimage.$ sudo docker run -d -p 80:80 docker/getting-started
To check if you have any existing running containers, you can run docker ps.
Create the Watchtower Docker container.
$ sudo docker run --detach \ --name watchtower \ --volume /var/run/docker.sock:/var/run/docker.sock \ containrrr/watchtowerCheck that Watchtower is running by using
docker. The status should beUp.$ sudo docker ps STATUS Up x seconds/minutes
You have now successfully installed and configured Watchtower to update your Docker container images regularly.
Additional Configuration
Watchtower has some additional configurations that can be changed using command line arguments.
Setting the Timezone
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/watchtowerAutomatically Removing Old Images
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 \
--cleanupMore Information
More Watchtower configuration options can be found in the documentation below.