Remove all Docker images, volumes, running in your system

In my one of the previous post, I shared methods to clean up Docker containers in your system. As I said before Containers are isolated from one another and bundle their software, libraries, and configuration files. Sometimes they are born with Storage volumes and network bridges.

Most importantly Docker Containers are created from Docker images and post removing the containers, images using which you created those containers still exist in your system. That would be eating up a considerable amount of space in your machine.

So there is a shortcut to delete all the images in your machine

docker image rm $(docker images -aq)

The above command removes all the images, to remove images with filter

docker image rm $(docker images --filter=reference='ruby:*') // would delete all ruby images irrespective of tag
docker image rm $(docker images --filter=reference='postgres:*') // would delete all postgres images irrespective of tag

If you are having unused images that are not referred to by any container docker itself provides a built-in command

docker image prune

If you are having some Dangling Images that have no relationship to any tagged images and you want to remove them.

docker image rm $(docker images -f "dangling=true" -q)

Once you are done with the images, you might need to clean up Volumes

To know what all Docker volumes exists in your system

docker volume ls 

To delete all the unused local volume with impigrity Docker itself provides a command

docker volume prune

If you want to remove volumes by force with impigrity use the below command

docker volume rm $(docker volume ls --format "{{.Name}}")

Lets clean up Network Bridges

Usually, when you spin up several docker-compose definitions, at your local system, it also creates network bridges for its context and needs. Here is how we clean them up in your system with impigrity.

To Remove all unused local network bridges docker itself has provided a command: -

docker network prune

To Remove all local network bridges by force with impigrity use the below command: -

docker network rm $(docker network ls --format "{{.ID}}")