How to Fix the “docker no space left on device” Error

Docker is software that is used to process and deliver multiple packages in the form of containers. These containers help allow the program to be free of the restrictions of its specific current environment. The “docker no space left on device” error is often invoked when utilizing the features of Docker. This article will shed some light on what causes this error and what steps can be taken to avoid the issue.

How to Resolve “docker no space left on device” Problem?

As always every problem has its causes. This error is no exception to that. Let’s check out why “docker no space left on device” issue is invoked on any system.

Reason: Memory is Full

The reason is very self-explanatory as the statement suggests. The system does not have any remaining space on it to perform the required function from the docker tool. There exist various methods through which, memory can be cleared up in the system.

Solution 1: Use System Prune

The system prune command is the most effective way to clean up space on your system for docker. This will remove any objects, images, etc that have not been utilized. To perform this task, simply run the command shown below:

$ sudo docker system prune
how to handle linux files and direc...

Be aware that some important files may also be deleted by the use of this command. The image below shows the process of system pruning:

Solution 2: Use Volume Prune

Instead of system prune, in some cases, it is better to utilize the Volume Prune command. With this command, all the volumes present locally on the system are removed. Volume prune will remove all the volumes that have not been utilized by any other container. Using the following command, a lot of space can be vacated:

$ sudo docker volume prune

Solution 3: Delete Manually

You can also perform deletion individually on docker. Below is the method through which this task can be performed with ease. Firstly,  retrieve the list of idle volumes. Execute the code that is shown below in the Linux terminal:

$ sudo docker volume ls -qf dangling=true

This should present any volumes that are orphaned/idle. You can use the following command to remove these idle volumes from the system:

$ sudo docker volume rm $(docker volume ls -qf dangling=true)

You can also manually delete the docker images using their names. To get their names, run this command in the terminal:

$ sudo docker image ls

Note down the repository that you want to remove and run the following command:

$ sudo docker rmi $(docker images | grep <image_name> | awk '{print $3}') --force

In this command, the repository name will be inserted in the place of the <image_name>. This should remove the specified image manually. The awk command is used to specify the print format whereas the “rmi” command acts as the removal command.

Solution 4: Clean the Cache

If the above solutions do not work then you can always check the cache and clean it which will free up some space. If you want to check how much space is being occupied by the cache, run this command:

$ sudo docker system df

The build cache section will show you how much space it is taking up. If it is a massive amount, you can clean it up by running this command in the terminal:

$ sudo docker builder prune

This will successfully clean up any cache that is present and hence will remove the “docker no space left on device” error.

Conclusion

The “docker no space left on device” error is invoked when the system runs out of space for the docker tool to be able to execute its commands. It can be resolved in multiple ways. You can automatically prune the entire system or the volume or you can manually remove the images and volumes. Furthermore, the cache can also be cleaned up to clear some more space. This article has provided a lot of detail to find out the reasons and solutions for each of these reasons.