Reclaim Your Disk
Disk Space Consumption
Creating images and running containers consumes disk space that later on you might want to reclaim. Here are some ways disk space is consumed unknowingly:
Stopped containers that were not removed by using the
--rmswitch on the docker run command or using the docker rm command once they are stopped.
Unused images: images that are not referenced by other images or containers.
Dangling images: images that have no name. This happens when you docker build an image with the same tag as before, the new one replaces it and the old one becomes dangling.
Manually removing these, one by one, can be tedious, but there are garbage collection commands that can help with that.
Reclaiming Disk Space
Most commands ask for an interactive confirmation, but if you want to run them unattended you can add the -f switch.
Here are the commands you can run to remove the items that you don’t need: