StasM
StasM

Reputation: 11012

Is there a way to clean docker build cache?

I am running a lot of builds using Docker in MacOS. Eventually, a lot of build cache is accumulating, e.g. this is what I see in docker system df:

YPE            TOTAL     ACTIVE    SIZE      RECLAIMABLE
Images          22        0         9.67GB    9.67GB (100%)
Containers      0         0         0B        0B
Local Volumes   0         0         0B        0B
Build Cache     1006      0         258GB     258GB

Is there a way to clean items from the build cache? I can see detailed list of them, e.g.:

CACHE ID       CACHE TYPE     SIZE      CREATED             LAST USED           USAGE     SHARED
045834a7a6e9   regular        11.1MB    3 weeks ago                             0         false
114ca5b7280f   regular        114MB     3 weeks ago                             0         false
27d6fcbb531d   regular        1.65kB    3 weeks ago                             0         false
3042a2a59d4f   regular        553kB     3 weeks ago                             0         false
3d70c1a312eb   regular        468MB     3 weeks ago                             0         false
658aaefc4cdd   regular        209MB     3 weeks ago                             0         false
7d5b48149871   regular        59.9MB    3 weeks ago                             0         false
86569a54d5d4   regular        16.5MB    3 weeks ago                             0         false

etc. with docker system df -v but the only way I see to remove any is completely wiping all Docker data, including images, etc. which I don't want to do. Is there any other way to make Docker to reclaim the space? I can see those objects but I can find no way of deleting them...

P.S.1 This question is not about how to delete images and containers. I know how to delete them, unfortunately deleting either does nothing to the "Build Cache" contents which continues to occupy space.

P.S.2 This is especially important on MacOS because there Docker operates within one specific allocated volume, which this way gets exhausted very quickly and I start getting "out of disk space" errors when building. Since the builds are done repeatedly, keeping data from old builds is not useful for me, so finding a way to delete old build caches would be great.

Upvotes: 74

Views: 62385

Answers (3)

Igor
Igor

Reputation: 1121

This command helped me to force clear all docker [compose] build/container/image/env caches. All environments will be deleted from memory and everything will be rebuilded.

docker system prune --all --force

Hope that helps!

Upvotes: 2

Ishan
Ishan

Reputation: 1339

docker builder prune

Removes build cache. Docs: docker builder prune

Upvotes: 100

IKo
IKo

Reputation: 5766

docker builder prune --all

more details: https://docs.docker.com/engine/reference/commandline/builder_prune/

Upvotes: 58

Related Questions