In my system there are multiple images of some app that I created.
All of the images I want to address have latest
tag (there might be other images with other tags).
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
image1 latest abcdefg1 5 minutes ago 1.00GB
and-image2 latest abcdefg2 6 minutes ago 2.00GB
might-have-img3 latest abcdefg3 7 minutes ago 2.50GB
How can I change all images with this tag to another tag?
(as you notice, repository
name is not uniform, so grep
on repository might not help)
Here's a way I found that works for me, for whoever needs it for future:
docker images | grep latest | awk '{print "docker tag " $1 ":" $2 " " $1 ":my_new_tag"}' | xargs -L1 -I %s -- sh -c %s
The command gets a list of all images, then grep
s over those with the wanted tag.
On each item in the list, we format it like this:
docker tag repository_fullname:latest repository_fullname:new_tag
Then each item is executed as a shell command. So it actually does the following:
$ docker tag image1:latest image1:new_tag
$ docker tag and-image2:latest and-image2:new_tag
$ docker tag might-have-img3:latest might-have-img3:new_tag