Remove all Docker containers/images

by||1 min read

Actually this is not too hard to achieve. We can just use docker ps to list all containers and use this list to stop each item in it. Before we can remove all containers we need to stop them first:

docker stop $(docker ps -a -q)

To remove all containers we just need to do the same with the rm command.

docker rm $(docker ps -a -q)

If you would like to remove all images just use the rmi command. But instead of ps (to list all containers) we use the images command:

docker rmi $(docker images -q)

That's it. Simple!

Thank you for reading this far! Let’s connect. You can @ me on Twitter (@debilofant) with comments, or feel free to follow. Please like/share this article so that it reaches others as well.

© Copyright 2022 - Ersocon - All rights reservedVer.