8 Solutions – How to fix “docker no space left on device” error {Update 2023}

Today I will let you know, how you can fix Docker no space left on device error easily. I will give you 8 solutions to get this monster out of your life. I assume that if you landed on this post, you already know about docker and how to install docker. So I won’t waste your precious time by talking about Docker again.

As this error “Docker no space left on the device” speaks about itself, the solution is –

  • To Clean up (prune) orphaned image files, Networks, docker volumes, inodes etc.
  • Add more space on your disk
  • Find out the root cause and fix it, which is causing this error like growing Docker logs using log rotate.

As you know Docker can be installed on any platform like Windows 10, Mac, Ubuntu, Debian, Redhat, CentOS and many other Linux distributions. I will try to cover solutions that are common as well as specific to the above-mentioned platforms. Let’s deep dive into types of problems and solutions.

There are many articles on the internet around this issue but nobody talks about all the scenarios that may result in this error. I will try to cover all these below-mentioned errors and solutions around them.

  • Docker no space left on device mac
  • Docker no space left on device windows 10
  • Docker no space left on device Ubuntu
  • Docker no space left on device Linux (other distributions)
  • Docker no space left on device unknown
  • Docker has no space left on the device but there is space
  • Docker no space left on device ec2 instance
  • Docker no space left on device centos Linux
  • Docker no space left on device overlay2 FS driver
  • Docker no space left on device var/lib directory
  • Issue of Docker no space on device in Docker-swarm

How to fix Docker no space left on device

Let’s talk about the solutions which are common and you should try first and common to all platforms on which you run Docker.

Solution-1 Perform system cleanup using “Docker system Prune” command (Recommended)

Let’s say if you are trying to download a docker image and you are getting “Docker no space left on the device“. It’s time to perform some housekeeping using the docker system prune command.

$ docker system prune

Caution – Before running this command, You need to understand, this command removes unused stopped containers, Images (both dangling and unreferenced ), networks, and optionally, volumes automatically, which you may require in future.

It will result in the following actions.

  • – 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]
docker no space left device on system fix using docker system prune

Press “y” per your requirement. But you will definitely get space free after running this command.

By default docker system prune command doesn’t remove volumes, as it contains data. If you want to remove or prune only unused volumes, then run.

$ docker system prune --volumes

You may need to manually stop containers and delete them if your prune command became unresponsive and unable to delete volumes.

In case, you want to remove all unused items including volumes in one single command using the “-a” or -all option.

 $ docker system prune --all
docker system prune all

To delete or prune your system without the prompt, you can use the “-f” or “–force” flag.

  $ docker system prune --all --force

Check docker disk usage to validate free space

$ docker system df
check docker system size using docker system df command

Solution-2 List and delete orphaned volumes and docker images manually

If you don’t want to follow solution-1 to prune automatically, but want to list and delete them manually with caution to free some space to fix “docker no space left on device”. Then follow the below-mentioned steps-

Step-1 List all the orphaned (Not in use) volumes first using the docker volume command.

$ docker volume ls -qf dangling=true

Step-2 Delete all listed dangling orphaned volumes using the “docker volume rm” command.

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

Step-3 Delete unused or orphaned docker images

List all images which are present on your system and look for images, which you think are not in use anymore.

$ docker image ls
List docker images

Input the docker image name in the following tiny script and delete orphaned images to get some free space in your system.

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

For example, I have given the <image name> “hello-world” and it got deleted. You need to use –force flag if it’s attached to any container.

Delete docker orphaned images

Or simply run

$ docker rmi <image name>

Remove images tagged with <none>, which are created while building an image and eats up significant space in your system.

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

Solution-3 Run docker volume prune

Sometimes system prune commands don’t get space free for you. In that case, you can simply run the volume prune command

$ docker volume prune
Docker volume prune command to fix docker no space left on device error

Solution-4 Change the default /var/lib/docker storage location (Root), if this partition/drive is full in your system

This is an advanced solution, in the case of solution 1 and solution 2 do not solve your “docker no space left on device issue”.

May be default docker storage partition or drive i.e. /var/lib/docker is full and you may need to give an alternate location to store your further docker containers data.

Below mentioned steps will help you to change the default docker storage from /var/lib/docker to /container/new_location/local_storage

Step-1 Create a new directory either on external storage or internal storage mount point

$ sudo mkdir  /container/new_location/local_storage 

Step2- Change permission of this directory

$ sudo chmod 777 /container/new_location/local_storage  

Step3- update docker.service present under /usr/lib/systemd/system

Open docker.service file with your favourite editor

$ sudo vi /usr/lib/systemd/system/docker.service

and update ExecStart option with a new storage location.

ExecStart=/usr/bin/dockerd -s devicemapper --storage-opt dm.fs=xfs --storage-opt dm.basesize=40GB -g /container/new_location/local_storage --exec-opt native.cgroupdriver=cgroupfs

Save and exit the docker.service file.

In the case of the overlay2 file system

  • Just add -g /container/new_location/local_storage in the existing ExexStart statement.
  • Something like ExecStart=/usr/bin/dockerd -g /container/new_location/local_storage -H fd:// –containerd=/run/containerd/containerd.sock

Step4- Remove the /var/lib/docker directory, if not required anymore

You can take one time backup of the /var/lib/docker directory to restore, in case required. Then you can delete it to recover some space in your system.

$ sudo rm -rf  /var/lib/docker 

Step5- Stop and reload docker service

Stop docker service.

$ sudo systemctl stop docker

Reload the docker daemon

$ sudo systemctl daemon-reload

Start docker service again

$ sudo systemctl start docker

check out this link for further details.

Solution-5 Inodes are full and you are getting error “docker no space left on device

If you are using Centos/ReHat/Amazon Linux, you may get device-mapper releasing inodes issue in docker. Even docker prune will not help you to get inodes free. It will still hang on to a lot of inodes, and you can only solve it by imploding docker by following commands.

Run the “df -i” command to check, the issue is occurring due to inodes got full for your docker storage mount point.

$ df -i 
  • Stop docker service
$ service docker stop
  • Take backup of your data first and then remove or delete /var/lib/docker default storage directory to release all inodes.
$ rm -rf /var/lib/docker
  • Start docker service again
$ service docker start

Solution-6 Change “per container size limit”, if you have enough space and still getting docker no space left on device

If your df -h command shows enough space and there is no inodes full issue. Then you may be hitting the “per container size limit” and you must change it.

For example, if you are using RedHat or Fedora Linux systems and then you know device-mapper is limited to 10GB per image and if your docker image is >=10 GB. You will get “docker error: no space left on the device”.

Below mentioned steps will help you to change per container size limit to get this issue solved-

Step1- Stop docker service

 $ sudo systemctl stop docker 

Step 2- Take a backup of your data first and then remove or delete /var/lib/docker default storage directory.

$ sudo rm -rf /var/lib/docker

Step3- Change device-mapper base (docker container) size from default 10G to 20G or more

Please note, once you will increase the size, you can’t reduce it. Also, you must have the required space available in your system to extend the default docker container size.

$ dockerd --storage-opt dm.basesize=20G
Change device-mapper base size docker

If you get below-mentioned error, just run “sudo rm -f /var/run/docker.pid” command. Then run the dockerd command again.

Error starting daemon: pid file found, ensure docker is not running or delete /var/run/docker.pid

Step4- Restart docker

$ sudo systemctl start docker

Check Docker service status

 $ sudo systemctl status docker 

Validate new setting

$ docker info

Solution7- Docker no space left on device on Mac system

If running the prune command shown solution1 release a little space and you are using Mac, You need to perform one extra step. You need to delete docker.raw file

Check the docker.raw size by visiting

Preferences > Resources > Advanced > Disk Image Location

Or use mac terminal to get space details

$ du -h docker.raw

Delete docker.raw file and restart docker for mac. This file will get created again with 0GB size and you will get a good amount of free space. This will fix your “docker no space left error on Mac” for sure. In my case, it got around 38 GB of space.

Solution8- Cleanup cache using builder prune

In case images and containers are not filling your space, then it may be cache. To check this, run

$ docker system df

Check for build-cache size, if it’s huge clean it up using the builder prune command.

$ docker builder prune
reclaim cache in docker builder prune

Conclusion

I hope the solutions presented in this post will help you to get rid of docker no space left on device error in your system. If you still face any issues, you can leave your comment and feedback with error details. I will try to help you resolve it to the best of my knowledge.

Let me know which solution helped you to fix the docker error via your comments.

Dev

I'm Dev, your friendly neighbourhood Tech Savy. I spend my days with gadgets, servers, and the occasional laugh-inducing software mishap. Think of me as your tech-savvy, glitch-prone buddy. If you've got questions, feedback, or just need someone to blame when your Wi-Fi goes haywire, I'm your guy!