73

I have built a pretty big image (1G) that has a lot of "infrastructure" in it for testing (Mongo, Kafka, etc.)

When trying to start this I get no space left on device errors. How can I fix this?

I've cleaned off stopped images and removed any images I don't absolutely need.

Greg
  • 10,696
  • 22
  • 68
  • 98

7 Answers7

133

If you get no space left on device error with Docker, you might be able to solve this easily with system prune.

I use Docker for Mac 17.03.

With docker UP and all your containers RUNNING, execute docker system prune -a

This should give the following dialog:

WARNING! This will remove:
- all stopped containers
- all volumes not used by at least one container
- all networks not used by at least one container
- all images without at least one container associated to them Are you sure you want to continue? [y/N]

Then press y to delete lots of containers, concluding (in my case) with: Total reclaimed space: 23.26 GB.

Now you can go back to work without even rebooting docker!

unthinkingly
  • 1,477
  • 1
  • 9
  • 3
  • This is a solution, can't imagine how increasing disk allocation could be a solution once it still leaves all those trash files there. – Machado Oct 19 '21 at 12:27
115

You can resize the virtual disk image size in Docker for Mac's Preferences in the Disk tab. This will increase the space without data loss.


In newer versions, the settings can be found in the Resources tab (sub-tab "Advanced"): Option name: Disk image size

Quoting Eddie
  • 1,501
  • 1
  • 11
  • 14
  • 4
    It depends, at some point your real disk will be full and increasing the virtual disk is not an option anymore :-) – Alexander Klimetschek Aug 27 '18 at 22:10
  • I also think this should be the correct answer now. – Patrick Klitzke Jun 02 '19 at 12:16
  • I agree that this should be the accepted answer as well. My use-case, I don't want to delete all my build cache as I was trying to re-work my Dockerfile so cacheable steps would not be invalidated. – leeman24 Sep 10 '19 at 16:58
  • 1
    In my case I had to go to Resources tab and Advanced section to change these. My Docker for Mac Community version 4.1.7 – Jared Feb 06 '20 at 16:58
  • 1
    I did this and the Docker.raw file did get smaller, but I never got the space back when going to About this Mac > Storage. I shrank the disk image size from 64GB to 8GB but the space didn't show up as being reclaimed in Storage. Any ideas? – SuperCodeBrah May 22 '21 at 13:17
  • Well, just increased my disk space to 256 GB.... Don't worry, disk space is cheap they said... This is not a solution. – Alex Barker Dec 02 '22 at 17:30
15

Check your directories of docker to locate your problem (on MAC this will be different but the same approach could help)

du -hs /var/lib/docker

You're able to see which folder is taking a lot of disk space by performing the same command on subfolders of /var/lib/docker :

  • For /var/lib/docker/volumes: You have to delete 'orphaned' volumes. You can also use docker volume ls -qf dangling=true to check the volumes. To delete the orphaned volumes: docker volume rm $(docker volume ls -qf dangling=true)

  • For /var/lib/docker/containers you have to check if you have a lot of stopped (or running) containers with docker ps = running containers and docker ps -a = all containers (running and stopped). To delete stopped containers: docker rm -v $(docker ps -aq). The -v flag will automatically delete the volume of the container

  • For /var/lib/docker/images you can delete all your unused images by using docker rmi $(docker images --filter "dangling=true" -q --no-trunc)

Also check GitHub to find some very useful scripts which delete you unused images/containers/volumes.

lvthillo
  • 28,263
  • 13
  • 94
  • 127
8

Try increasing your disk space. This is what worked for me. Docker -> preferences -> disk -> Disk image size (increase it) -> Apply

Edwin Rodriguez
  • 153
  • 1
  • 4
  • 11
3

You can update size of a hard drive available for vm in $HOME/.docker/machine/machines/default/config.json

Alex Lapa
  • 1,149
  • 11
  • 21
2

You can click on the Docker icon at the top, then preferences. Go to the reset tab and click on remove all data.

Christopher Francisco
  • 15,672
  • 28
  • 94
  • 206
0

You can always drop and recreate the boot2docker vm anew to make sure only the needed images/containers are built/imported anew. If you keep hitting the space issue you might want to give your boot2docker vm bit more space, see Docker increase disk space

Community
  • 1
  • 1
Mykola Gurov
  • 8,517
  • 4
  • 29
  • 27