wesupport

Need help?

Our experts have had an average response time of 13.14 minutes in February 2024 to fix urgent issues.

We will keep your servers stable, secure, and fast at all times for one fixed price.

How to automatically update Docker Container using Watchtower

by | Oct 15, 2020

Are you looking for steps to update the Docker Container? Here’s how we do it.

Here at Bobcares, we have seen several such Docker related queries as part of our Docker Hosting Support for Docker users, web hosts, and online service providers.

Today we’ll take a look at updating the Docker Container process.

 

Why do we need to update the Docker Container?

You might have deployed the container a long time ago. After that, there came many security issues, and also they were patched in the image.

If you don’t update the container then it could face many security issues. In case, if you are stopping the container, pulling down the image, and then recreating it then it could take a long time.

So updating the Container is the best option. Moreover, there is a container called Watchtower that will automatically check for image updates and, if it finds any changes in a container’s base image, it will gracefully shut it down and restart it with a new image and the same options used when the containers were initially started.

 

How to update Docker Container

Now let’s take a look at how our Support Engineers update the Docker Container.

 

Deploying Watchtower

There are two different ways to deploy Watchtower. The first one will monitor all the containers and update them, whereas the second one will monitor and update only a specific container.

Let us have the Watcher monitor all of those containers. Before it, let us check the status of the containers with the command docker ps. It will display the list of containers that are currently running. Here, you need to make a note of the created columns and the age of the containers that are displayed.

Now it’s time to deploy the Watchtower. For that, open a terminal window and run the below command.

docker run -d –name watchtower -v /var/run/docker.sock:/var/run/docker.sock v2tec/watchtower

But in order to run the above command, the user must belong to the Docker group. However, if the user doesn’t belong to the docker group then run the below command.

sudo usermod -a -G docker USERNAME

In the above command, the USERNAME is the name of the user to be added. Then log out and log back in so that the above changes take effect.

Give Watchtower a moment to do its thing and the CREATE times will have changed. The process is very quick.

 

Watching a single container

You can also deploy Watchtower in such a way that it will only monitor a single, specific container.

We’re considering that the Shipyard is already deployed (for Docker management). Also, ensure that it is always up to date. If your Shipyard container is named shipyard, the command for Watchtower would be:

docker run -d --name watchtower -v /var/run/docker.sock:/var/run/docker.sock v2tec/watchtower shipyard

After running the above command, only the Shipyard container will be monitored and automatically updated.

 

The caveat and the trick

Yes, there is a caveat. But, here it is only one to be bothered. However, the Watchtower must be always running so that it does its thing.

Of course, there will be some outages when Watchtower does its thing. But you can avoid them by doing the following:

1. Deploying the Watchtower container
2. Keep issuing the docker ps command until you see the containers have updated
3. Stop the Watchtower container

This will stop the purpose of automating containers on a regular basis, but if container uptime is crucial to your business, this could be a way to avoid that. Also, you can setup a cron job to run it automatically.

[Need any further assistance with Docker related queries? – We’re available 24*7]

 

Conclusion

In short, the Watchtower automatically updates the Docker container. Today, we saw how our Support Engineers update the Docker Container.

Are you using Docker based apps?

There are proven ways to get even more out of your Docker containers! Let us help you.

Spend your time in growing business and we will take care of Docker Infrastructure for you.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

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

Categories

Tags