Docker cleanup

Delete all containers

docker rm $(docker container ls -a -q)

Delete all unnamed images

docker rmi $(docker image ls | grep "<none>" | tr -s ' ' | cut -d ' '  -f 3)

docker image ls lists all images,
grep "<none>" selects all that have the tag (or repository! or part of name!) “<none>” ,
tr -s ' ' merges sequences of spaces to a single space,
cut -d ' ' -f 3 splits each line at the space and gives the third column (the image id).
The list of ids is then passed on to docker rmi to be deleted.

Use at your own risk!

This entry was posted in Virtualization and tagged by swk. Bookmark the permalink.

About swk

I am a software developr, data scientist, computational linguist, teacher of computer science and above all a huge fan of LaTeX. I use LaTeX for everything, including things you never wanted to do with LaTeX. My latest love is lilypond, aka LaTeX for music. I'll post at irregular intervals about cool stuff, stupid hacks and annoying settings I want to remember for the future.