Home > Categories > Docker > Docker Cleanup: Remove Container, Images, Build Cache, Volume etc

Home > Docker Cleanup: Remove Container, Images, Build Cache, Volume etc

Docker Cleanup: Remove Container, Images, Build Cache, Volume etc

Updated:

10 Dec 2020

Published:

10 Dec 2020

Frequent docker cleanup is necessary for maintain healthy empty space on your computer.

When you are building docker container then you never get it right the first time. This will build up unnecessary cache storage.

If you run out of space then you can no longer start docker until you have free space.

So before things go out of hand do the following to see what can be removed.

To read rest of the article please Purchase Subscription

docker system df

docker system df ubuntu
Tap/click to enlarge and pinch to zoom.

The docker is running in Ubuntu 20.04 but the OS doesn't matter. Docker cli is same across all operating systems.

To clean up everything use the following command

docker system prune -a

Tap/click to enlarge and pinch to zoom.

You can force it by using docker system prune -a -f but I wouldn't recommend it when using manually.

Because of habit you may end up deleting all of your work.

But force option is helpful with docker-compose to clean up everything before you create a new build.

Then verify that everything is cleaned with docker system df

Tap/click to enlarge and pinch to zoom.

You can also prune each thing individually as follows

docker image prune -a
docker container prune
docker volume prune
docker network prune

You can force them all with -f suffix and check if its deleted by replacing prune with ls.

Free users cannot comment below so if you have questions then tweet me @apoorvmote. I would really like to hear your brutally honest feedback.

If you like this article please consider purchasing paid