Docker: "You don't have enough free space in /var/cache/apt/archives/"

Viewed 11481

I have a dockerfile which when I want to build results in the error

E: You don't have enough free space in /var/cache/apt/archives/

Note that the image sets up a somewhat complex project with several dependencies that require quite a lot of space. For example, the list includes Qt. This is only a thing during the construction of the image, and in the end, I expect it to have a size of maybe 300 MB.

Now I found this: https://unix.stackexchange.com/questions/578536/how-to-fix-e-you-dont-have-enough-free-space-in-var-cache-apt-archives

Given that, what I tried so far is:

  • Freeing the space used by docker images so far by calling docker system prune
  • Removing unneeded installation files by calling sudo apt autoremove and sudo apt autoclean
  • There was also the suggestion to remove data in var/log, which has currently a size of 3 GB. However, I am not the system administrator and thus wary to do such a thing.

Is there any other way to increase that space?
And, preferably, is there a more sustainable solution, allowing me to build several images without having to search for spots where I can clean up the system?

4 Answers

Converting a @Dre suggestion into the code, you might want to use Docker prune command for containers, images & volumes

docker container prune
docker image prune
docker volume prune

You can use these commands in sequence:

docker container prune; docker image prune; docker volume prune

Free Space without removing your latest images

Use the following command to see the different types of reclaimable storage (the -v verbose option provides more detail):

docker system df
docker system df -v

Clear the build cache (the -a option will remove unused build cache):

docker builder prune -a

Remove dangling images ( tagged images, old and previous image builds):

docker rmi -f $(docker images -f "dangling=true" -q)

Increase Disk image size using Docker UI

Docker > Preferences > Resources > Advanced > adjust Disk image size > Apply & Restart

TLDR;

run

docker system prune -a --volumes

I tried to increase the disk space and prune the images, containers and volumes manually but was facing the issue again and again. When I tried to check the memory consumption on my machine, I found a lot of memory consumed by ~/Library/Containers/com.docker.docker location. Did a system prune which cleaned up a lot of space and docker builds started working again.

Related