WatchTower for Automating Docker Container Updates

I’m currently running a Synology NAS and Docker Hub to run a self-hosted GitLab instance. GitLab is awesome and very user friendly, however they are constantly updating thier CE platform and when utilizing a docker instance, the Admin -you, will need to frequently update the container to maintain the most recent version is deployed.

This is where WatchTower comes in. WatchTower is a very simple to establish automation container that will monitor and update your Docker containers (including itself) while you spend your time more efficiently ie., scrolling Instagram, LOL.

Download the Image

Let’s get started. First download the Image using the Docker GUI.

WatchTower image successfully downloaded

Login

Second, SSH into your Synology and execute the following:


sudo -i

Enter your user password and continue. This will execute all future commands as the root user (careful!).

Create and Run the Container

Then execute this command in the terminal window:


docker run -d --name watchtower -v /var/run/docker.sock:/var/run/docker.sock containrrr/watchtower -e TZ:America_New_York --cleanup --schedule 0 0 0 * * * 

In-Depth Breakdown

This command will tell Docker to create and run a new container and name it watchtower. It also asks Docker to bind the Docker sock as a volume reference so it can monitor all of the containers via the docker.sock. This is why we are required to use the SSH route. Synology does not allow us to so this through the native Docker Hub (without editing an existing JSON file).

Let’s break down the command; It first calls “Docker run -d –name watchtower” this instructs Docker hub to create a new container with the name watchtower. The following “-v /var/run/docker.sock:/var/run/docker.sock” instructs the container to bind docker.sock of this new container to the Docker Hub’s instance to essentially listen for system notifications on image updates and thus allows us to begin monitoring the containers.

The next portion designates the image to use to build the watchtower container; “containrrr.watchtower”.

The “-e TZ:America_New_York” specifes the timezone that the container should reference. This setting should match your timezone. The list of available timezones can be found here.

It then specifies “–cleanup” to remove all old volumes and “–schedule 0 0 0 * * *” to set the poll frequency. “0 0 0 * * *” is a cron expression that checks for updated images every night at midnight.

Also Note

You can also set the interval every 60 seconds to confirm everything is working by setting the schedule to 0 * * * * *. Note that logs will not reflect that any containers are up to date. The logs will only record if an image is found to be newer than the image created for the currently running container.

Conclusion

That should have you up and running. You can now enjoy more free-time to scroll your favorite social media platform. Happy Dockering!

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.