How to Fix This Error - Docker Error: No Space Left on Device
Often you may gets an error if you are using the Docker container on your instance, Docker error: no space left on device.
By default the Docker Engine is use the location /var/lib/docker to store the images and container runtime environment. So, It might be the disk space is full which has disk mounted to /var/lib/docker and you need to verify the volume size with free/occupied using the command du.
$ du -sh /var/lib/docker
Then, clear or remove unused Docker images or stopped containers completed and will get some free space in /var/lib/docker. Just the options below,
Remove docker images with Name or Id,
$ docker image rm IMAGE_NAME/IMAGE_ID
Remove docker container with Name or Id,
$ docker container rm CONTAINER_NAME/CONTAINER_ID
Delete orphaned volumes with all volumes listed in the docker volume,
$ docker volume rm $(docker volume ls -qf dangling=true)
Delete all the images and download them again, execute the command below,
$ docker rmi $(docker images -a -q)
docker images -a = List out all the images with an option -a
docker images -a -q = And delete them all with an option -q additionally
Use the docker system prune instead of the above commands, but this would be very carful when you execuet it.
$ 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]
Then type the word "y" and hit the enter button, will be cleard all stopped containers, dangling images, dangling build cache and networks if not used by at least one container