How To Cleanup Docker Resources and Clear Space On Your Machine

In this post, We’ll take a look at Docker’s “clear” command to see how it can be used to remove all the containers and images that are on the machine and clear some space.

The clear command is one of Docker’s many powerful commands which you should know about if you’re using their toolset for managing running systems.

In this post, I will share with you two commands I use to clear some space from my development machine. When developing solutions with Docker after a few days or weeks of development work a machine can have many images and containers that are either running or not running and taking space, resources and clutter the hsot.

Delete All Containers

The following command will delete all the containers that are not running from the systems.

docker rm -vf $(docker ps -a -q)

Delete All Images

If you are building docker images you are probably consuming a lot space that can be freed. The following command will delete all the images that are on the system.

docker rmi -f $(docker images -a -q)

Conclusion

As a best practice, it is always a good idea to run maintenance tasks every week or two and optimize the system.


Posted

in

,

by