We here at AssetBytes are big fans of Docker! Don’t know what Docker is? Docker is a popular containerization software and you read more about Docker on Wikipedia or on the Docker Website
The purpose of this post is not give an overview of Docker or it’s commands but if you start using Docker extensively you will want to keep in mind the following key Docker cleanup or system pruning commands that we here at Assetbytes find very useful. Note, if you are using Docker Desktop then you can use the GUI to see what’s running and cleanup/delete containers and images but usually not the Docker volumes. Besides if you want to clean up ‘everything’ Docker related at once then the following Docker commands are very useful.
Docker Containers
To see a list of containers on your machine, execute the following command
docker ps -a
To remove a specific container from the above list, execute
docker rm <container id>
Docker Images
To see a list of the images on your machine, execute the following command
docker images -a
To remove a specific image from the above list, execute
docker rmi <image id>
To remove all images at once, execute
docker rmi $(docker images -a -q)
Docker Volumes
To see a list of the docker volumes created on your machine, execute the following command
docker volume ls
Note: It’s not volumes but volume
To remove a specific volume from the above list, execute
docker volume rm <volume name>
To remove all volumes at once, execute
docker volume prune
Docker System
To cleanup everything, i.e. to delete docker containers, images, network etc in one command execute
docker system prune -a
Note: Use the above command with caution as it will indeed wipe all the docker artifacts from your system. Well everything except for docker volumes, to remove even the docker volumes, after you execute docker system prune -a, you have to execute docker volume prune also.