Arcyno
Arcyno

Reputation: 4603

Docker build cache keeps growing

In my continuous delivery process I deploy every night a container with the last build of my application. But with each iteration the docker build cache is growing... Here are the commands applied every night :

docker rm $(docker stop $(docker ps -a -q --filter ancestor=myApplication --format="{{.ID}}")) 
docker rmi $(docker images -f "dangling=true" -q)
docker build -t myApplication . --rm
docker run -d -p 9090:8080 -v C:\localFolder:/usr/local/mountedFolder myApplication

when I check with docker system df, I see that the build cache is growing with every build. Is there a way to make sure the unused cache is deleted ?

Upvotes: 6

Views: 4584

Answers (1)

BMitch
BMitch

Reputation: 263637

The build cache is part of buildkit, and isn't visible as images or containers in docker. Buildkit itself talks directly to containerd, and only outputs the result to docker. You can prune the cache with:

docker builder prune

And there are flags to keep storage based on size and age. You can see more in the docker documentation: https://docs.docker.com/engine/reference/commandline/builder_prune/

Upvotes: 11

Related Questions