DEV Community

goffity
goffity

Posted on • Updated on

Update all docker images already pulled.

When we want to update all images that pulled. This is a command to use update all images at once. (This command will pull the latest tag)

docker images | grep -v REPOSITORY | awk '{print $1}' | xargs -L1 docker pull
Enter fullscreen mode Exit fullscreen mode

I found this command a long time ago and I cannot remember the reference. I am sorry for the owner.


Edit 2021-12-21

Today I found a problem on MacOS with this command and fixed to use

docker images | grep -v REPOSITORY | awk 'BEGIN{OFS=":"} {print $1,$2}' | xargs -L1 docker pull
Enter fullscreen mode Exit fullscreen mode

Discussion (2)

Collapse
nandoabreu profile image
Fernando Abreu

That command will update all images, but will pull maybe more than you need. For instance, I use python:3.6-alpine (40MB) and postgres:13-alpine (158MB). That command downloads a new python:latest (880MB) and a new postgres:latest (314MB).

The command to update your existing images is:

docker images | grep -v ^REPO | sed 's/ \+/:/g' | cut -d: -f1,2 | xargs -L1 docker pull
Enter fullscreen mode Exit fullscreen mode

(my postgres:13-alpine was updated now, to 160MB)

And to clean unused and untaged images after that, run:

docker image prune
Enter fullscreen mode Exit fullscreen mode
Collapse
goffity profile image
goffity Author

Thanks, It's very helpful.