Docker error : no space left on device
The current best practice is:
docker system prune
Note the output from this command prior to accepting the consequences:
WARNING! This will remove: - all stopped containers - all networks not used by at least one container - all dangling images - all dangling build cacheAre you sure you want to continue? [y/N]
In other words, continuing with this command is permanent. Keep in mind that best practice is to treat stopped containers as ephemeral i.e. you should be designing your work with Docker to not keep these stopped containers around. You may want to consider using the --rm
flag at runtime if you are not actively debugging your containers.
Make sure you read this answer, re: Volumes
You may also be interested in this answer, if docker system prune
does not work for you.
I had the same error and solve it this way:
1 . Delete the orphaned volumes in Docker, you can use the built-in docker volume command. The built-in command also deletes any directory in /var/lib/docker/volumes that is not a volume so make sure you didn't put anything in there you want to save.
Warning be very careful with this if you have some data you want to keep
Cleanup:
$ docker volume rm $(docker volume ls -qf dangling=true)
Additional commands:
List dangling volumes:
$ docker volume ls -qf dangling=true
List all volumes:
$ docker volume ls
2 . Also consider removing all the unused Images.
First get rid of the <none>
images (those are sometimes generated while building an image and if for any reason the image building was interrupted, they stay there).
here's a nice script I use to remove them
docker rmi $(docker images | grep '^<none>' | awk '{print $3}')
Then if you are using Docker Compose to build Images locally for every project. You will end up with a lot of images usually named like your folder (example if your project folder named Hello, you will find images name Hello_blablabla
). so also consider removing all these images
you can edit the above script to remove them or remove them manually with
docker rmi {image-name}
Check that you have free space on /var as this is where Docker stores the image files by default (in /var/lib/docker).
First clean stuff up by using docker ps -a
to list all containers (including stopped ones) and docker rm
to remove them; then use docker images
to list all the images you have stored and docker rmi
to remove them.
Next change the storage location with a -g option on the docker daemon or by editing /etc/default/docker
and adding the -g
option to DOCKER_OPTS
. -g
specifies the location of the "Docker runtime" which is basically all the stuff that Docker creates as you build images and run containers. Choose a location with plenty of space as the disk space used will tend to grow over time. If you edit /etc/default/docker
, you will need to restart the docker daemon for the change to take effect.
Now you should be able to create a new image (or pull one from Docker Hub) and you should see a bunch of files getting created in the directory you specified with the -g option.