Retention/Cleanup of intermediate layers

Greetings!

Running docker 20.10.14 on Ubuntu.
We got a multi-stage Dockerfile building regularly a ~500MB image.

Intermdiate cache layers are gradually taking more and more space, and I don’t understand how to get rid of them. It’s reaching almost 100 GB of mysterious cache layers eaten up in /var/lib/docker/overlay2/

Tried so far:

  • docker image prune -a
  • docker rmi on docker images filtering dangling
  • untagging the related images and doing either above
    They don’t even show in docker images

We found out that using docker system prune would clear them, but i’m not particularly happy about the part where it can delete data volumes.

Is there no other way to do this ?

Thanks a bunch…

The command docker builder prune is ment to be used to cleanup the build cache.

I run the the command with and without -a to illustrate the difference:

me@node:~$ sudo docker builder prune
WARNING! This will remove all dangling build cache. Are you sure you want to continue? [y/N] y
Total reclaimed space: xyzB

me@node:~$ sudo docker builder prune -a
WARNING! This will remove all build cache. Are you sure you want to continue? [y/N] y
Total reclaimed space: xyzB

OH WOW… How did I never manage to find this in doc ?!

Thanks so much…