How to fix docker error no space left on device?
Sometimes you must clean up your disk so that you can download the docker image and run it. But if you do not have sufficient space available on your disk then you might end up with the error no space left on device
.
In this blog, we are going to see a number of ways to fix this error because I had this issue many times while working with docker.
Table of Content
- Using docker system prune (docker system prune, docker system prune --volume, docker system prune --all)
- Delete orphaned volumes
- Delete unused images
- Default docker storage .i.e. - /var/lib/docker
- Docker space issue for Mac
1. docker system prune
The first command which comes to my mind for freeing space is to run the following command is docker system prune
(Note: - docker system prune
can be run with different parameter, so please read through all the option before running the command)
1docker system prune
But always run this command with caution because it will just wipe everything for you and if you want to retain some of your other docker containers then you might lose those.
Once you will run the above command it is going to ask for the confirmation -
1WARNING! This will remove:
2 - all stopped containers
3 - all networks not used by at least one container
4 - all dangling images
5 - all dangling build cache
6
7Are you sure you want to continue? [y/N]
You can press Y
and it will free up some space for you.
docker system prune --volumes
The docker system prune
prunes images, containers, and networks but it never prunes/delete the volumes
associated with the docker container. If the docker system prune
does not work for you then try to delete the volumes
by supplying the --volumes
-
1docker system prune --volumes
docker system prune --all
If you want to prune images, containers, networks along with volumes then you should supply --all
parameter -
1docker system prune --all
2. Delete orphaned volumes
The second approach I would take to remove all the orphaned volumes associated with the docker. But before you remove all of the orphaned volumes, I would recommend you to list out all the orphaned volumes before deleting it -
1docker volume ls -qf dangling=true
Now you can run the following command to remove all the orphaned volumes -
1docker volume rm $(docker volume ls -qf dangling=true)
3. Delete unused images
Before coming to this step I would highly encourage you to check the step-2 where we have deleted the volumes.
Alright now I am assuming you have already tried removing the unused volumes associated with your docker container and now first check how many docker images
you have onto your system -
1docker image ls
The above command will list out all the docker images available. Please take note of the image name which you want to delete.
Now you can run the following command by replacing the <image_name>
-
1docker rmi $(docker images | grep `<image_name>` | awk '{print $3}')
Or you can run the following command -
1docker rmi {image-name}
4.Default docker storage .i.e. - /var/lib/docker
If all the previously mentioned 3 steps do not work for you then it's time to check the default docker storage
and generally it's around ~6GB
. If you are working with docker for quite some time then it is highly possible that you might have consumed all the available default docker storage
.
In general speaking the default docker storage
location is - /var/lib/docker
Now we need to change the default docker storage
location from - /var/lib/docker
to something else /app/sample_direction/my_local_storage
.
Step 1 : Create storage directory
Run the following mkdir
command (Note - Change the directory name as per your requirement)
1mkdir /app/sample_direction/my_local_storage
Step 2 : Change the permission
Make sure to change the directory permission after you have created the directory -
1chmod -R 777 /app/sample_direction/my_local_storage
Step 3 : Update docker.service
Now update the docker.service
file which generally present under /usr/lib/systemd/system
1vi /usr/lib/systemd/system/docker.service
It will open up docker.service
in edit mode. Now you need to update your default docker storage path to - /app/sample_direction/my_local_storage
1ExecStart=/usr/bin/dockerd -s devicemapper --storage-opt dm.fs=xfs --storage-opt dm.basesize=40GB -g /app/sample_direction/my_local_storage --exec-opt native.cgroupdriver=cgroupfs
(Note:If the storage device is overlay2)
In case if your storage device is overlay2 then you might need to add add -g /apps/newdocker/docker
to your docker.service
Step 4 : Remove /var/lib/docker
Now we need to delete the default docker directory .i.e. - /var/lib/docker
1rm -rf /var/lib/docker
Step 5 : stop and restart docker service
First, stop the docker service -
1systemctl stop docker
Next, reload the Docker daemon -
1systemctl daemon-reload
Now start your docker daemon -
1systemctl start docker
5. Docker space issue for Mac
In case you are working on Mac and then you could try one more approach to free up some space by deleting Docker.raw
file.
Mac OS is a little special and it creates a docker.raw
file for local docker storage and over time this file piles up. You can locate the file here -
1Preferences > Resources > Advanced > Disk Image Location
You can check the file size and then delete it. It should fix your issue error no space left on device
.
Here are some reference for further reading -
- Stackoverflow - Docker error : no space left on device
- Docker.com - https://docs.docker.com/engine/reference/run/#clean-up---rm
Learn more On Kubernetes -
- Setup kubernetes on Ubuntu
- Setup Kubernetes on CentOs
- Setup HA Kubernetes Cluster with Kubespray
- Setup HA Kubernetes with Minikube
- Setup Kubernetes Dashboard for local kubernetes cluster
- Setup Kubernetes Dashboard On GCP(Google Cloud Platform)
- How to use Persistent Volume and Persistent Volume Claims in Kubernetes
- Deploy Spring Boot Microservice on local Kubernetes cluster
- Deploy Spring Boot Microservice on Cloud Platform(GCP)
- Setting up Ingress controller NGINX along with HAproxy inside Kubernetes cluster
- CI/CD Kubernetes | Setting up CI/CD Jenkins pipeline for kubernetes
- kubectl export YAML | Get YAML for deployed kubernetes resources(service, deployment, PV, PVC....)
- How to setup kubernetes jenkins pipeline on AWS?
- Implementing Kubernetes liveness, Readiness and Startup probes with Spring Boot Microservice Application?
- How to fix kubernetes pods getting recreated?
- How to delete all kubernetes PODS?
- How to use Kubernetes secrets?
- Share kubernetes secrets between namespaces?
- How to Delete PV(Persistent Volume) and PVC(Persistent Volume Claim) stuck in terminating state?
- Delete Kubernetes POD stuck in terminating state?
Posts in this Series
- (docker run -d) Why Does a Docker Container Stop Automatically?
- Attach and detach from Docker's process?
- How I Change Name of My Docker Repository and Rename Images?
- How to set-up Cron Jobs in Docker Containers?
- 4 Ways to copy file from localhost to docker container
- Multiple commands execution in Docker Compose?
- How to push Docker Images to AWS ECR(Elastic Container registry)?
- How to Copy Docker images from one host to another host?
- What is persistent storage in docker and how to manage it
- Docker Installation on MacOS, Linux and Windows
- Docker - ADD, Update, Export Environment variable
- How to fix-Docker docker failed to compute cache key not found
- How to fix docker driver failed programming external connectivity on endpoint webserver?
- How to fix docker error executable file not found in $PATH?
- How to expose port on live containers?
- How to expose multiple ports with Docker?
- How to restart single docker container within multiple docker container?
- How to edit file within Docker container or edit a file after I shell into a Docker container?
- How to fix Error starting docker service Unit not found?
- How to remove old, unused images of Docker?
- How to fix docker error invalid reference format error?
- How to fix requested access to the resource is denied?
- How to fix Docker error cannot delete docker container conflict unable to remove repository reference?
- How to fix docker error no space left on device?
- How to connect localhost from docker container?
- Docker COPY vs Docker ADD?
- 6 Ways to fix - Got permission denied while trying to connect to the Docker daemon socket?
- 6 Ways to fix – Docker COPY failed: stat no source files were specified