Deleting my entire /var/lib/docker is not ok for me. These are a safer ways:
Solution 1:
The following commands from the issue clear up space for me and it's a lot safer than deleting /var/lib/docker or for Windows check your disk image location here.
Before:
docker info
Example output:
Metadata file:
Data Space Used: 53.38 GB
Data Space Total: 53.39 GB
Data Space Available: 8.389 MB
Metadata Space Used: 6.234 MB
Metadata Space Total: 54.53 MB
Metadata Space Available: 48.29 MB
Command in newer versions of Docker e.g. 17.x +
docker system prune -a
It will show you a warning that it will remove all the stopped containers,networks, images and build cache. Generally it's safe to remove this. (Next time you run a container it may pull from the Docker registry)
Example output:
Total reclaimed space: 1.243GB
You can then run docker info again to see what has been cleaned up
docker info
Solution 2:
Along with this, make sure your programs inside the docker container are not writing many/huge files to the file system.
Check your running docker process's space usage size
docker ps -s #may take minutes to return
or for all containers, even exited
docker ps -as #may take minutes to return
You can then delete the offending container/s
docker rm <CONTAINER ID>
Find the possible culprit which may be using gigs of space
docker exec -it <CONTAINER ID> "/bin/sh"
du -h
In my case the program was writing gigs of temp files.
(Nathaniel Waisbrot mentioned in the accepted answer this issue and I got some info from the issue)
OR
Commands in older versions of Docker e.g. 1.13.x (run as root not sudo):
# Delete 'exited' containers
docker rm -v $(docker ps -a -q -f status=exited)
# Delete 'dangling' images (If there are no images you will get a docker: "rmi" requires a minimum of 1 argument)
docker rmi $(docker images -f "dangling=true" -q)
# Delete 'dangling' volumes (If there are no images you will get a docker: "volume rm" requires a minimum of 1 argument)
docker volume rm $(docker volume ls -qf dangling=true)
After :
> docker info
Metadata file:
Data Space Used: 1.43 GB
Data Space Total: 53.39 GB
Data Space Available: 51.96 GB
Metadata Space Used: 577.5 kB
Metadata Space Total: 54.53 MB
Metadata Space Available: 53.95 MB