The Linux Page

My hard drive looks full but I have nearly nothing installed and just a few dockers...

Istanbul, it's full.

Where Did My Disk Space Go?

I suppose with the title on this page, you already understood that Docker is the culprit... Yep! It's using a lot of disk space to store all of those images. One image can very easily be over 1Gb and if you have a VirtualBox system with many images, you end up eating a lot of your disk space very quicly!

How Did You Discover the Issue?

I ran the following command:

sudo ncdu -qx /

Did some other work for a little while, then checked the results. By default, the largest folder was shown at the top:

/var

You can simply select the folder and hit enter to go inside. I did that a few times and found out that the directory with the most data was owned by Docker.

How Did You Resolve the Issue?

There is actually a very simple command line option to prune all the docker images that are not currently in use:

docker image prune

However, that does not prune all the data, only the images. When you run a docker, it creates a volume which won't go away on its own. To clean everything, you want to clean the system instead:

docker system prune

The command asks you to confirm your move. Say yes and then check your used disk space again:

df .

In my case, the disk space used went from 91% to 51% and I gave 256Gb of space on that VPN disk!

Next I think I'll look at having another disk where I can place the Docker files. That way I can make sure that my boot drive doesn't get filled up that fast. Docker may know to auto-delete some old files, but from what I've seen, it does not seem to do it on its own. So if you build many dockers all the time, running prune once in a while is certainly a good idea all around.

Note:

If you have images that you do not use, you probably want to remove them too and re-run the prune command afterward. You can see the list of images with:

docker images
  ... or ...
docker images ls

And you can remove an image with:

docker rmi <image ID>
   ... or ...
docker rmi <repository name>:<tag>

See below for you the second command is useful.

Can't Delete Docker Image?

At times, I get the following error trying to delete a docker image:

$ docker rmi 9c6f07244728
Error response from daemon: conflict: unable to delete 9c6f07244728 (cannot be forced) - image has dependent child images

As we can see, the message just says that some other image depends on this image and thus you cannot just delete it.

By default, I tend to use the image identifier, which is unique, to delete an image. However, if you tagged an image, docker creates a form of safe soft link to that tag. It then looks like you have two images.

The fact is that you have to first delete the tags. Maybe you have a list that looks like this:

REPOSITORY   TAG         IMAGE ID       CREATED        SIZE
golang       latest      9c6f07244728   6 months ago   208Mb
golang       1.19        9c6f07244728   6 months ago   208Mb

When trying to remove that image, it gives you the error above.

To be able to remove the image, you need to first remove one of the tags. This is done using the REPOSITORY name and the TAG name separated by a colon:

docker rmi golang:1.19

Then you can remove the image using its identifier (you can also use the other tag: golang:latest in my example above.