22/03/2025

Cleaning up Docker cache and free up space

By snorlaxprime

When you are running Docker in raspberry pi, the space are premium, so after several update to my docker image, it is hogging the space until I am running out of storage, which makes the system slow beyond imagination. So here we go.

Step 1. Check how much disk space Docker is using

You can use the following command

docker system df

As you can see above I have 6 images, but 5 that is active and I can reclaim 214.6MB, and I have 5 containers but only 4 that is active.

Step 2. Remove unused image

Now that I know that I have one unused image, I want to remove it, so use the following command to remove the image that are not associated with any container. Before you do this step make sure all the docker container that you want is running. You can first check using the following command prior to pruning

Once you are happy that all your containers are running only then issue the pruning command below

docker image prune

As you can see above the old image is pruned and 112.7MB was reclaimed.

If you can to prune all image that are not associated to a running container you can use the following command

docker image prune -a -f

Step 3. Removing volumes

We can also remove the volume by using the following command

docker volume prune

In this instance we don’t have any volume that are not associated with containers.

we can check the volume using the following command

docker volume ls

I hope this is useful, as I manage to reclaim quite a bit of disk space. If you need more details explanation on how the docker cache works you can find it in the following location

Removing stopped container

You can use the following command to remove the container that is no longer running.

https://depot.dev/blog/docker-clear-cache

https://fleetstack.io/blog/raspberry-pi-free-disk-space