Delete docker image with all tags

(λx.x)eranga
Effectz.AI
Published in
2 min readApr 23, 2018

Scenario

I have docker image with several tags. I want to remove this docker image with all its tags. If I do that manually I want to list the tags and delete one by one.

Command

I have found some way to delete the images and all its tags with single command. It combine various commands with linux pipe |

Following are the break down of all commands that I have used

1. docker images

List all docker images. I have quite a lot of docker images. :)

2. grep

grep the images that contain the name chainz

3. tr -s

tr utility copies the given input to produced the output with substitution or deletion of selected characters. In here I’m removing spaces of previous command output.

4. cut -d

cut command allows to extract the specific part from a text. In here I’m extracting the tag part.

5. xargs -I

xargs command allows to convert input of standard input into argument of another command. In above command it returns a list of tags, I can echo the full name of the image with the tag by using xargs

To delete the image with all its tags, I can xargs the docker tag inputs to docker rmi command.

Reference

  1. http://thushw.blogspot.com/2017/03/docker-delete-all-tags-of-image.html
  2. https://www.cyberciti.biz/faq/tag/linux-tr-example/
  3. https://www.geeksforgeeks.org/cut-command-linux-examples/
  4. https://shapeshed.com/unix-xargs/

--

--