Download the latest IMG for your Docker Containers

I found it cumbersome to update one container at a time, so I wrote a little snippet to update all my containers in one call. I normally run docker-compose where you just have to stand in the folder where you have your docker-compose.yml file and write docker-compose up -d in this scenario I didn’t have docker-compose installed.

First I recommend running the below command, It’s always good to delete any unused images.

docker image prune -a

The snippet utilises the AWK (made from the developers – Aho, Weinberger, and Kernighan) command in Unix to skip the first row and only print the column 1 (REPOSITORY) from the cmdlet “docker images

So below will go through all your images and download the latest (default) image available.

for i in $(docker images --filter "dangling=false" | awk '(NR>1){print $1}')
    echo "Working on $i"
    docker pull $i

There are a better ways of doing this, but as I’m a PowerShell Fanboy I tend to go back to my roots and use the code that resembles PS the most 😛

Once you have all the latest Docker images you can go ahead and stop the container you’d like to update and then re run them with and do not forget to add the mounts if you had any.

docker stop ...
docker rm ...
docker run -d --name ... --restart=always -v /my/data/dir:/var/lib/... 

Great documentation is available here. ->

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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