7

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 ?

1 Answer 1

12

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/

Sign up to request clarification or add additional context in comments.

4 Comments

What is the difference with the commande docker system prune -a ?
@Arcyno docker builder prune only prunes the build cache, with options you specify. docker system prune -a cleans everything that it lists when you run the command, one of those things being the build cache.
Last question : docker rmi $(docker images -f "dangling=true" -q) does not clear unused images ?
@Arcyno it clears dangling images, those without a tag and just appear as an image id.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.