DEV Community

Cover image for Updating Docker Apps automagically with Watchtower✨🐳
Jonas Scholz
Jonas Scholz Subscriber

Posted on • Edited on

5 1 1 1 1

Updating Docker Apps automagically with Watchtower✨🐳

Have you ever deployed a Docker app on a server, but everytime you push a new version of your image to a Docker registry you need to manually restart your app? If you want to automate this restarting, this blog post is for you! I am now going to show you how you can do this with literally 1 simple command using Watchtower!

This tutorial assumes that you already have a flow to automatically build and push your containers to a registry. If you do not have that, I suggest you to read and follow this tutorial or simply use a ready-to-go solution such as Sliplane

Let's get started! 🚀

Setup

First, run your container that you want to automatically update. Then, run the following command after replacing username, password, and container_to_watch

docker run -d \
  --name watchtower \
  -e REPO_USER=username \
  -e REPO_PASS=password \
  -v /var/run/docker.sock:/var/run/docker.sock \
  containrrr/watchtower container_to_watch --debug --interval 300
Enter fullscreen mode Exit fullscreen mode

This will run the watchtower container (containerrr/watchtower) in the background (-d), name it watchtower, and pass in the username and password for your Docker container registry (-e REPO_USER=username -e REPO_PASS=password)

Watchtower will now periodically check if your Docker image has changed (in your remote repository!) and pull a new version once it has changed. It will then gracefully shut down your old container and restart it with the same configuration but with a new image. The default polling interval is 24 hours, which is quite conservative if you ask me. You can change the polling interval with --interval x where x is the number of seconds to wait. If you want to check for updates every 5 minutes you would add --interval 300

Conclusion

That's it! Now your cool dockerized app should update everytime you push a new image to your Docker repository. If you want to deploy a Docker app without all of the devops pain and without any Docker repositories, check out Sliplane

Tiugo image

Modular, Fast, and Built for Developers

CKEditor 5 gives you full control over your editing experience. A modular architecture means you get high performance, fewer re-renders and a setup that scales with your needs.

Start now

Top comments (0)

nextjs tutorial video

Youtube Tutorial Series 📺

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series 👀

Watch the Youtube series