57

When I am trying to build the docker image I am getting out of disk space error and after investigating I find the following:

df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        4G   3.8G     0 100% /

How do I fix this out of space error?

Pritam Banerjee
  • 17,953
  • 10
  • 93
  • 108

7 Answers7

105
docker system prune

https://docs.docker.com/engine/reference/commandline/system_prune/

This will clean up all images, containers, networks, volumes not used. We generally try to clean up old images when creating a new one but you could also have this run as a scheduled task on your docker server every day.

Nick Spicer
  • 2,279
  • 3
  • 21
  • 26
  • 24
    You need to pass the `--volumes` flag to prune the volumes as well. Without this only 'unused containers, networks, images (both dangling and unreferenced)' will be pruned. – jannis Jul 27 '18 at 08:28
  • I feel that this is only a temporary solution. We have over 14Gb free disk space and Docker still says that no space is left. We called "docker system prune" and it worked, but only for a while. Not to mention that the database was deleted as well but thats our fault (always make regular backups people!) – Ziga Petek Oct 04 '19 at 07:07
25

use command - docker system prune -a This will clean up total Reclaimable Size for Images, Network & Volume..... This will remove all images related reclaimable space which are not associated with any running container.....

Run docker system df command to view Reclaimable memory

In case there is some Reclaimable memory then if above command does not work in first go then run the same command twice then it should cleaned up.... I have been experiencing this behavior almost on daily basis..... Planning to report this bug to Docker Community but before that want to reproduce this bug with new release to see if this has been fixed or not with latest one....

tryingToLearn
  • 10,691
  • 12
  • 80
  • 114
Abhishek Jain
  • 3,815
  • 2
  • 26
  • 26
  • 13
    Be very careful with `-a`. This will wipe every image on your system that doesn't have a container associated with it. Usually just `docker system prune` is sufficient. – Josh Nov 27 '19 at 02:51
  • 1
    I did mention about user has to be careful when using -a as it will remove all images for which containers are not running.... – Abhishek Jain Nov 27 '19 at 12:18
  • Be very careful with -a. This will also remove unused networks and you may lose network connectivity. – Lawrence Patrick Dec 09 '20 at 04:23
  • The statement "if above command does not work in first go then run the same command twice" helped me. Not sure, why it did not free up space in 1 shot. – tryingToLearn Nov 02 '22 at 05:58
15

Open up the docker settings -> Resources -> Advanced and up the amount of Hard Drive space it can use under disk image size.

Nico
  • 1,094
  • 13
  • 17
6

If you are using linux, then most probably docker is filling up the directory /var/lib/docker/containers, because it is writing container logs to <CONTAINER_ID>-json.log file under this directory. You can use the command cat /dev/null > <CONTAINER_ID>-json.log to clear this file or you can set the maximum log file size be editing /etc/sysconfig/docker. More information can be found in this RedHat documentation. In my case, I have created a crontab to clear the contents of the file every day at midnight. Hope this helps!

NB:

  1. You can find the docker containers with ID using the following command sudo docker ps --no-trunc
  2. You can check the size of the file using the command du -sh $(docker inspect --format='{{.LogPath}}' CONTAINER_ID_FOUND_IN_LAST_STEP)
kaushik
  • 2,308
  • 6
  • 35
  • 50
2

Going to leave this here since I couldn't find the answer.

Go to the Docker GUI -> Prefereces -> Reset -> Uninstall

Completely uninstall Docker.

Then install it fresh using this link

My docker was using 20GB of space when building an image, after fresh install, it uses 3-4GB max. Definitely helps!

Also, if you using a macbook, have look at ~/Library/Containers/docker*

This folder for me was 60 GB and was eating up all the space on my mac! Even though this may not be relevant to the question, I believe it is vital for me to leave this here.

DUDANF
  • 2,618
  • 1
  • 12
  • 42
1

Nothing works for me. I change the disk images max size in Docker Settings, and just after that it free huge size.

troger19
  • 1,159
  • 2
  • 12
  • 29
  • 1
    Wow, I didn't see this option! Was wondering why my Windows showed 60GB free disk space, but Docker containers said "Not enough disk space left" - I had my limit at 50GB (which was all used up) - set it to 200 and it worked! – Alex Jul 13 '19 at 18:44
  • well the command should be as mentioned above, the thing is it doesnt work for me.. only manually clicking on a button – troger19 Apr 09 '21 at 09:33
1

Not sure if this is still relevant, but in case of docker system prune not working, and if you don't want to go docker system prune -a, you should pick and delete images using either

  • docker image prune --filter

or

  • Picking and deleting them from Docker for Dekstop
cconsta1
  • 737
  • 1
  • 6
  • 20
L0t
  • 31
  • 4