Monday, March 13, 2017

Docker: delete all tags of image

Handy one liner to delete all tags of a particular docker image (on Linux):

docker images | grep rabbitmq | tr -s ' ' | cut -d ' ' -f 2 | xargs -I {} docker rmi{}  

Here are the image tags that this one-liner removes:

thusharaw@denali ois-rabbitmq (thushara/rabbitv1)*$ docker images | grep rabbitmq                   2017031300          6fb1ed865ae6        3 hours ago         179 MB                   2017031307          6fb1ed865ae6        3 hours ago         179 MB                   2017031007          21b84ae0586e        2 days ago          179 MB                   201703100           43d51d243631        2 days ago          179 MB                   201703107           08927efd735e        2 days ago          179 MB                   201703109           646cb7852d8e        2 days ago          179 MB

Let's break down the on-liner:

1) docker images => 

get the images

2) grep rabbitmq

find the tags you care about

3) tr -s ' '

convert all repeating contiguous spaces to a single space so we can easily index to a specific column, the tag in this case

4) xargs -I {} docker rmi{} 

pass the thusly recovered tag to the `docker rmi` command, but use xargs to change the stdout of the previous cmd to a cmd line arg (which is what `docker rmi` works with)

1 comment:

Philips Huges said...

Its a wonderful post and very helpful, thanks for all this information. You are including better information regarding this topic in an effective way.Thank you so much

Personal Installment Loans
Payday Cash Advance loan
Title Car loan
Cash Advance Loan