A few intensive hours building Docker containers quickly used up all the allocated space.
Deleting Docker images can be done using -f to force deletion of images that are used in other containers that remain.
docker images docker rmi <IMAGE_ID> -f
Deleting Docker containers:
docker ps docker rm <CONTAINER_ID>
What if you got tens of images? Still easy.
There are multiple ways of deleting Docker images depending on how they’re used.
The dangling images are not tagged and not used by any container. You can remove these images using (-f flag confirms the operation):
docker image prune -f
If you instead want to remove all images that are not referred in any container:
docker image prune -a
Cleaning containers is an easy task. You can clear only containers that are not running. The following command will stop all running containers:
docker container stop $(docker container ls -aq)
Now that we don’t have any running containers we can completely remove them using:
docker container rm $(docker container ls -aq)
Check this post and learn how to quickly delete Docker containers and images if you’re running on Windows.