If you are playing around with many docker images, the storage may be fillup in no time. Then it’s time to do the cleaning up of all images and volumes. But please really really careful, because this command will delete everything that docker created, no matter whether it’s still running or not.
1. Delete container and volume
Delete the whole container and its volume. The running container will be stopped and the volume got deleted.
docker rm -vf $(docker ps -a -q)
2. Delete docker images
While the first command deletes the container and its volume, the image is still on the system. So we’ll delete all of the docker images.
docker rmi -f $(docker images -a -q)
3. Cleanup the leftover
Sometimes two commands above are not enough to clean up all space taken by Docker. So we’ll clean up using these two commands.
docker system prune -a --volumes sudo rm -fr /var/lib/docker/*