Docker - No space left on device
How to solve the Docker error 'No space left of device'
NOTE: this post will be more for Docker Desktop for Mac but this is applicable across devices.
If you develop with Docker, you are bound to run into this problem:
no space left on device
When you’re using Docker locally for development (good practice!), this can be frustrating when you’re building a lot. Let’s dive a little bit deeper, remembering that this blog tries to keep things in “bite-sized pieces”.
Why does this happen?
A quick answer to this is that it has everything to do with running out of your partitioned space when you installed/configured Docker. Docker just can’t fit anything else it needs to on your device. Please read the Docker docs on how it works if you need a refresher.
You could throw more resources at this problem…if you have them to spare. However, if you set these settings sufficiently or don’t have extra resources to spare, there’s another way.
If I can’t/don’t want to use more resources, what then?
Easy. This is likely because you have unused “things” hanging around (e.g. images, networks, etc). Docker comes with a handy command to fix this:
$ docker system prune
WARNING! This will remove:
- all stopped containers
- all networks not used by at least one container
- all dangling images
- all dangling build cache
Are you sure you want to continue? [y/N]
Type y
and press enter
and you’re good to go (after it runs…).
TIP: it will help you immensely if you run it on a regular basis!
BONUS: Is docker system prune
hanging ?
Keep in mind this can take quite some time to run. This can happen, for instance, when you use multistage builds during development, etc.
However, sometimes it does. I found this happends especially if you have a larger amount of “uncleaned” images hanging around. Don’t get me wrong, it’s a great tool so use it when you can!
Since most of the time, it’s due to the images, you can clean the images separately (which seems to work better sometimes).
Remove containers not in use:
$ docker rm $(docker ps -a -q)
Remove images not in use:
$ docker rmi $(docker ps -a -q)
Remove networks not in use:
$ docker network prune
Also, some people say they’ve had success restarting Docker. I have never needed to restart docker in order to solve this problem so I can’t say 100% that it would work.
Well, that’s where we’ll leave it to keep it “bite-sized”. Hope this helps someone 😉