Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 332
Arcyno Avatar asked Jul 23 '26 01:07

Arcyno


1 Answers

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/

like image 134
BMitch Avatar answered Jul 24 '26 22:07

BMitch