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:
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 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:
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:
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:
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.
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.
To enlarge a logical partition let's find a list of these volumes, usually they are mapped to directories in the Linux tree:
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:
The print command will list the current logical partitions, remember your partition number and enter the command:
Enter the new disc size, note not how much the space will increase, but the new value! For example, 40GB.
Next, let's increase the file system size through a similar utility in one command!
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:
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:
After that we will delete the containers with the command:
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!
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!