×


Updating Docker Container automatically

Are you trying to update Docker Container? This guide you show you how.


Sometimes, your Docker container needs to be updated to improve security and to prevent security issues.
Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform Docker related Tasks and Software Installation.

In this context, we shall look into how to update Docker Container.

Why do you need to update Docker Container?

As earlier stated, If you do not update the container then it could face security issues. The process of stopping the container, pulling down the image, and then recreating it could take a long time.

Therefore, 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 perform update for a Docker Container?

To update a docker container, simply follow the following process;

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 execute the following command;

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


Note that to be able to run the above command, the user must belong to the Docker group. However, if the user does not belong to the docker group then run the below command;

sudo usermod -a -G docker USERNAME


"USERNAME" here represents the name of the user to be added. Then log out and log back in so that the above changes can take effect.

In this process, you should be patient with Watchtower  as it could take some time for it to complete.

How to implement Watchtower on a single server?

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

We are considering that the Test is already deployed (for Docker management). Also, ensure that it is always up to date. If your Test 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 test


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

 

Working with Watchtower?

Sometimes, 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 Support in fixing Docker related issues? – We are available to help you today.]


Conclusion

This article will guide you on how to update Docker Container using Watchtower.