While you build docker images, it is likely that many untagged images get piled up. This topic covers how to delete those images and keep your docker host neat and clean.
###For docker verison >= 1.13
If you are using docker version 1.13
and above, the following commands will do the trick.
####Complete System Cleanup
To clean up, all unused containers, images, network, and volumes, use the following command.
docker system prune
Recommended: Learn Docker Technologies for DevOps and Developers
To individually delete all the components, use the following commands.
docker container prune
docker image prune
docker network prune
docker volume prune
###For Docker versions below 1.13
To clean up containers, first, you need to clean up your containers. So that all the unwanted images can be deleted without dependency problems.
####Delete all Exited Containers
docker rm $(docker ps -q -f status=exited)
####Delete all Stopped Containers
docker rm $(docker ps -a -q)
####Delete All Running and Stopped Containers
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
Delete all “none” Images
docker rmi $(docker images | grep "^<none>" | awk '{ print $3 }')
Delete all Dangling Images
sudo docker rmi $(sudo docker images -f "dangling=true" -q)