comment 0

Keep your Docker images up-to-date with a script

Keep your Docker images up-to-date with a script

Every now and then I want to download the latest images for my Docker containers. Instead of going through every image (which gets old really fast), I came up with a simple shell command:

docker ps --format='{{.Image}}' | xargs -L1 docker pull

This will list your current images and pull the latest for each. All you have to do next is remove the outdated containers and recreate them based on the new images.

UPDATE: for each updated container, you can then recreate an updated container with a single command line (I keep a document with a list of all these commands for easy access. One day I may automate the whole process). Let’s say you want to recreate the crashplan container:

docker stop crashplan && docker wait crashplan && docker rm -f crashplan && docker run --name crashplan ...

docker wait is important, otherwise docker rm will fail to remove the container, since it is still running.

UPDATE 2: If you want to fully automate the management of your docker containers, I highly recommend looking at the docker-compose command, as suggested by Vadim Gusev in the comments below. I had stayed away from docker-compose all this time, when it was exactly what I was wishing for to manage my containers. Basically I can now run a single bash file that will recreate/update my containers, and even enable auto-start on them. If there’s interest, I may update this article in the future to describe the procedure on QNAP devices.

Filed under: IT

About the Author

Posted by

Go Core Team Lead @ (remote), previously Windows Team Lead @ Plex (remote), Architect, Codebase Whisperer, DevOps enthusiast, Continuous Learner