СHRISTMAS
WHEEL OF FORTUNE

Tap the button and win a guaranteed prize right now!

By registering, you are signing up to receiving e-mails.
JT
September 23 2024
Updated September 23 2024

No space left on device: remove Docker error

Linux

Errors when configuring a service are a natural process that every engineer faces in his part of routine work. One of them is Docker error : no space left on device, such an error can be very confusing, because nowadays in Linux the space is divided by file system quite flexibly and it is quite possible to run out of space or run out of quota.

How do I resolve a Docker error?

This problem has two main causes at the root, which say that:

the space in the disc partition on the path /var/lib/docker is full and requires more space. This problem occurs because of the large amount of space occupied by Docker objects as well as the local repository.
Docker quota space has run out - this is also one of the most common reasons when the configuration specifies the memory limit that Docker can use. This feature is useful to avoid filling up excessive disc space.

To check whether you have enough or insufficient disk space, use the command that will display a list of file systems and the space they occupy:

df -H
Disk space
Screenshot №1 — Disk space

Note that the /var/lib/docker folder can be located either on the root partition / logical disc or separately /var. In this case, the target folder is located on the /dev/vda2 logical partition. If the size of your disc space does not allow you to load the image or store data, you should clear the space from unnecessary files or enlarge the disc.

Clearing Docker files

If you didn't have the needed projects in Docker, you can completely clean up the system with the command:

docker system prune -af

Docker will go through the local repository, repositories, containers and remove them, but before doing so make sure there are no running containers with the command:

docker stop $(docker ps -q)
Clear container
Screenshot №2 — Clear container

In order to delete files in a specific way, use subcommands, e.g. cleaning images in the local repository will be done with the command:

docker image remove $(docker image ls -q)
Remove image
Screenshot №3 — Remove image

To delete other objects, use similar subcommands: volume, container, network, etc. If you need to delete a specific file, first browse the list and delete the necessary one:

docker image ls
docker image remove [container-name]
Remove dedicated image
Screenshot №4 — Remove dedicated image

After checking the available space on the disc again with the command df -H, in case there is still not enough space go to the point below.

Disc Extension

If you don't have sufficient resources than you can perform actions on powerful cloud servers. Serverspace provides isolated VPS / VDS servers for common and virtualize usage.

Create Server
Screenshot №5 — Create Server

Increase the device's disc space by expanding the hypervisor's virtual storage or select a different disc for the machine. The space will then be increased, however, it must be allocated to logical volumes and the file system.

If you are using LVM to work with discs, please see the separate detailed guide.

To enlarge a logical partition let's find a list of these volumes, usually they are mapped to directories in the Linux tree:

df -H
Disk space
Screenshot №6 — Disk space

In this case it is /dev/vda2, we use a pre-prepared utility to change the partitioning of the disc table. Note that you need to specify your partition instead of /dev/vda2:

apt update && apt install parted && parted /dev/vda2

The print command will list the current logical partitions, remember your partition number and enter the command:

resizepart [partition-number]

Enter the new disc size, note not how much the space will increase, but the new value! For example, 40GB.

Change size of volume
Screenshot №7 — Change size of volume

Next, let's increase the file system size through a similar utility in one command!

resize2fs
Resize file system
Screenshot №8 — Resize file system

By default, all the free space of the logical partition will be occupied by the file system, after which you can check the freed space with a well-known utility:

df -H

But what if there is enough space for the Docker container and the error is the same? Most likely it's the allocated quota.

Increase Docker quota

A solution in a couple of lines that will allow you to override the value of variables and specify more space for Docker. To explicitly specify resources, we need to restart the containers with the new parameters. Let's stop all current tasks:

docker stop $(docker ls -q)

After that we will delete the containers with the command:

docker container prune

Set the new parameters via options. Note that you should be careful when choosing values for containers, as they may use up unnecessary system resources!

docker run -d --name my_container -m 512m --memory-swap 1g --cpus=‘2’ nginx

The -m option specifies a RAM usage limit of 512MB, --memory-swap 1GB of virtual memory, and 2 CPU cores. By increasing the values from the default values, the problem will be solved!

Vote:
5 out of 5
Аverage rating : 5
Rated by: 1
33145 North Miami, FL 2520 Coral Way apt 2-135
+1 302 425-97-76
700 300
ITGLOBAL.COM CORP
700 300

You might also like...

We use cookies to make your experience on the Serverspace better. By continuing to browse our website, you agree to our
Use of Cookies and Privacy Policy.