To run docker rmi composed with grep use following line:

docker images | grep none | tr -s " " | cut -d" " -f3 | xargs docker rmi -f

end tl;dr

At some day I run out of disk space. Disk analyzing tools such as baobab and ncdu shown enormous amounts of disk volume taken by /var/lib/docker.

Lets check the images we have on machine:

docker images

Ok, a lot of images tagged as <none>  sized over 1GB, and technically they are junk.

Here we can do docker system prune. But there is a risk to remove needed images and I've a mood to do some sh piping instead.

docker images | grep none

Looks better. Now lets select IMAGE_ID field of em.

docker images | grep none | cut -f3 #wont work

And the selection by regular find command failed, because docker uses precalculated amount of spaces instead of tabs. So here we can use tr to remove trailing spaces and then use cut with space as delimiter:

docker images | grep none | tr -s " " | cut -d" " -f3

After getting a list of IMAGE_IDs. We can pass them to docker rmi as first argument using xargs.

docker images | grep none | tr -s " " | cut -d" " -f3 | xargs docker rmi -f

Now all images tagged as <none> are removed.

So what can I say. The same result was achieved by docker system prune, but this was a good practice of sh scripting for me.

Thanks for reading,
Happy Coding.