How to fix Docker error: no space left on device

You will find below how to solve the Docker error : no space left on device . There are two similar solutions. The first is the long winded whereas the second is the fastest.

Solution 1 :

You would first need to delete the volumes that have become orphaned in Docker. This can be done by executing the volume command in Docker. Since this deletes any directory or folder that is not a volume in /var/lib/docker/volumes , you would need to be certain no important documents are stored in them.

Now for the cleanup, you would need to make sure the commands below would not delete any important documents you may have.

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

Further commands:

To help you list all dangling volumes, issue the command below:

docker volume ls -qf dangling=true

To list all volumes however, run the command :

docker volume ls

Now you would need to get rid of all the unused Images. First delete the <none> images ( generated sometimes while the building image process is interrupted).

You can use the script below to remove them :

docker rmi $(docker images | grep ‘^<none>’ | awk ‘{print $3}’)

In case Docker Compose is one of your set of tools that allow you to locally build Images for every one of your projects, many images will get accumulated . Their names will usually contain your folder. You would want to consider removing them as well by editing the script above or manually by using command :

docker rmi {image_name}

Read: How to clean up unused Docker containers, images and volumes

Solution 2:

In this alternative solution, run the commands below :

docker system prune

This will delete all containers that were stopped as well as all volumes and networks and that are not used by any container. It will also remove all dangling images.

Now in order to clean your system you would first have to remove containers by invoking the command below :

docker rm $(docker ps -aq)

For the images, run the command :

docker rmi $(docker images -q)

But you will also be able to remove them using the command :

docker rm ID_OF_CONTAINER and docker rmi IMAGE_ID.

amin nahdy

Amin Nahdy, an aspiring software engineer and a computer geek by nature as well as an avid Ubuntu and open source user. He is interested in information technology especially Linux based ecosystem as well as Windows and MacOS. He loves to share and disseminate knowledge to others in a transparent and responsible way.

Leave a Reply

Close Menu