Reclaim Your Disk

In this lesson, you will be made aware of how Docker can take up disk space and how you can reclaim that space.

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 --rm switch 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.

  • Unused volumes.

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:

Get hands-on with 1200+ tech skills courses.