Need to quickly clean up your Docker environment? Here's a simple list of Linux and PowerShell commands to remove old images, volumes, and containers. Just copy, run, and you're good to go π
Are you looking for an easy way to clean up your Docker environment? I recently came across several threads on another website where users were asking how to clean up their Docker servers.
This included everything from images and volumes to containers with volumes, or even the entire environment. It's fairly easy, but since it's not something we do every day, most people would need to look it up each time.
The commands you will find below is for Linux only. If you are looking for Windows commands (PowerShell) please go here. Windows Commands.
Delete All Containers Including Their Volume π§
To delete all containers and their volumes on your system, you can use the below command.
docker rm -vf $(docker ps -aq)
Delete All Images π¦
To delete all images on your system, you can use the command below.
docker rmi -f $(docker images -aq)
Delete Containers In Exited State ποΈ
docker rm $(docker ps -a -f status=exited -q)
Delete Containers In Created State π
docker rm $(docker ps -a -f status=created -q)
Delete Everything β οΈ
π€
If you are looking for a way to prune your whole system, you can use the command below. Please be aware that it will remove EVERYTHING NOT IN USE! It's a great way to free up diskspace if you are running low.
docker system prune -a --volumes
Running it will result in the following output in your terminal.
WARNING! This will remove:
- all stopped containers
- all networks not used by at least one container
- all volumes not used by at least one container
- all images without at least one container associated to them
- all build cache
Windows (PowerShell) πͺ
PowerShell treats $() as a subexpression operator, just like in the shell, but it needs to be used differently in some cases. Due to that, we can try using ForEach-Object for more robustness when running the command.
Delete All Containers Including Their Volume π§
To delete all containers and their volumes on your system, you can use the below PowerShell command.
This command is the same across Windows and Linux. It will give you the same warning as it does on Linux.
docker system prune -a --volumes
WARNING! This will remove:
- all stopped containers
- all networks not used by at least one container
- all volumes not used by at least one container
- all images without at least one container associated to them
- all build cache
Summary
I hope you got your problem solved and learned something at the same time.
Resources π
Below are links for reference to the locations with documentation I have used to create this Docker clean up tutorial.
My name is Christian. I am a 28-year-old Solution Architect & Software Engineer with a passion for .NET, Cloud, and Containers. I love to share my knowledge and teach other like-minded about tech.
A Docker Clean Up Cheat Sheet
Need to quickly clean up your Docker environment? Here's a simple list of Linux and PowerShell commands to remove old images, volumes, and containers. Just copy, run, and you're good to go π
β Christian Schou
A Docker Clean Up Cheat Sheet
Are you looking for an easy way to clean up your Docker environment? I recently came across several threads on another website where users were asking how to clean up their Docker servers.
This included everything from images and volumes to containers with volumes, or even the entire environment. It's fairly easy, but since it's not something we do every day, most people would need to look it up each time.
Below is a quick command to help you clean up different components. Just copy the command and run it on your system. Bon appΓ©tit! π€
Linux π§
The commands you will find below is for Linux only. If you are looking for Windows commands (PowerShell) please go here. Windows Commands.
Delete All Containers Including Their Volume π§
To delete all containers and their volumes on your system, you can use the below command.
Delete All Images π¦
To delete all images on your system, you can use the command below.
Delete Containers In Exited State ποΈ
Delete Containers In Created State π
Delete Everything β οΈ
Running it will result in the following output in your terminal.
Windows (PowerShell) πͺ
PowerShell treats
$()
as a subexpression operator, just like in the shell, but it needs to be used differently in some cases. Due to that, we can try usingForEach-Object
for more robustness when running the command.Delete All Containers Including Their Volume π§
To delete all containers and their volumes on your system, you can use the below PowerShell command.
Delete All Images π¦
To delete all images on your system, you can use the PowerShell command below.
Delete Containers In Exited State ποΈ
Looking for a way to delete all the containers in an exited state? Remember to manually remove the volumes after, if any is attached.
Delete Containers In Created State π
Looking for a way to delete all the containers in an created state? Remember to manually remove the volumes after, if any is attached.
Delete Everything β οΈ
This command is the same across Windows and Linux. It will give you the same warning as it does on Linux.
Summary
I hope you got your problem solved and learned something at the same time.
Resources π
Below are links for reference to the locations with documentation I have used to create this Docker clean up tutorial.
My name is Christian. I am a 28-year-old Solution Architect & Software Engineer with a passion for .NET, Cloud, and Containers. I love to share my knowledge and teach other like-minded about tech.
On this page