Docker storage space error solution (operate carefully, it will affect the original easy image, do not operate if you are not proficient)

insert image description here

Error content

[root@Dream package]# docker build -t imapp .
[+] Building 21.0s (6/19)
 => [internal] load build definition from Dockerfile                                                                                                 0.1s
 => => transferring dockerfile: 907B                                                                                                                 0.0s
 => [internal] load .dockerignore                                                                                                                    0.1s
 => => transferring context: 2B                                                                                                                      0.0s
 => [internal] load metadata for docker.io/library/centos:7                                                                                          2.5s
 => [ 1/15] FROM docker.io/library/centos:7@sha256:be65f488b7764ad3638f236b7b515b3678369a5124c47b8d32916d6487418ea4                                  0.2s
 => => resolve docker.io/library/centos:7@sha256:be65f488b7764ad3638f236b7b515b3678369a5124c47b8d32916d6487418ea4                                    0.1s
 => => sha256:be65f488b7764ad3638f236b7b515b3678369a5124c47b8d32916d6487418ea4 1.20kB / 1.20kB                                                       0.0s
 => => sha256:dead07b4d8ed7e29e98de0f4504d87e8880d4347859d839686a31da35a3b532f 529B / 529B                                                           0.0s
 => => sha256:eeb6ee3f44bd0b5103bb561b4c16bcb82328cfe5809ab675bb17ab3a16c517c9 2.75kB / 2.75kB                                                       0.0s
 => ERROR [internal] load build context                                                                                                             18.2s
 => => transferring context: 1.45GB                                                                                                                 18.1s
 => [ 2/15] RUN mkdir /data                                                                                                                          0.9s
------
 > [internal] load build context:
------
ERROR: failed to solve: write /var/lib/docker/overlay2/pg3tim64h8tebbvpq5vhkqfbo/diff/ZIM-23.1.5.x86_64.all.tar: no space left on device

problem analysis

An error was reported during the Docker build. The error message shows that there is not enough disk space. This error usually occurs during the build process of the Docker image, and this problem occurs when the local disk space is insufficient.

In order to solve this problem, you can try the following methods:

  1. Clean up disk space: Delete unnecessary files or directories to free up disk space. You can df -hcheck disk usage with command and rmdelete unnecessary files with command.

  2. Clean up Docker images: Use docker image prunecommands to clean up Docker images that are no longer in use.

  3. Adjust Docker configuration: You can free up space by deleting unused Docker images, containers, and volumes. Run docker system prunethe command to clean up Docker resources.

  4. Expand disk space: If the above methods do not solve the problem, you may need to consider expanding disk space or replacing the disk.

Here, we first look at the distribution of disk space
insert image description here
and then we switch disk space (note that it will affect the original running docker container)

problem solved

To make Docker use /dev/mapper/centos-homethe partition's mount point /homeas its storage path, you can do so by editing Docker's configuration file and modifying its storage driver. Here are some steps for your reference:

  1. Open the configuration file for the Docker service with a text editor /etc/docker/daemon.json(create the file if it does not exist):

    sudo vi /etc/docker/daemon.json
    
  2. Add the following content to the file, setting data-rootto /home(or the path you want):

    {
      "data-root": "/home"
    }
    
  3. Save and close the file.

  4. Restart the Docker service for the configuration to take effect:

    sudo systemctl restart docker
    

Docker will now use /dev/mapper/centos-homethe partition as its storage path. Make sure the target partition has enough capacity to store Docker's images, containers, and other related data.

Note that modifying Docker's storage path may require making appropriate changes to file permissions to ensure that Docker properly accesses and operates on the required files. Also note that this will use /homespace from the partition and may have an impact on other system files or applications, so proceed with caution.

preventive action

If the restart fails, you can perform the following operations to view the error message:

  1. Run the following command to view the status information of the Docker service:

    systemctl status docker.service
    

    This displays the current status of the Docker service and possible error messages.

  2. Run the following command to view details related to the Docker service in the syslog:

    journalctl -u docker.service -xe
    

    This displays logs related to the Docker service, which may contain additional details related to errors.

By viewing these outputs, you can get more error information about the failure of the Docker service for further troubleshooting and resolution.
If the error message "Unable to get the full path to root (/dev/mapper/centos-home/docker)" is reported, it means that Docker /dev/mapper/centos-home/dockerencountered a problem in obtaining the full path of .

This error may be caused by Docker being unable to resolve the given path. Please make sure /dev/mapper/centos-homethat /dev/mapper/centos-home/dockerthe and paths exist in the system and have the correct permissions.

You can check and fix the problem by following the steps below:

  1. Confirm /dev/mapper/centos-homethat /dev/mapper/centos-home/dockerthe two paths of and exist. You can run the following command to check:

    ls -l /dev/mapper/centos-home
    ls -l /dev/mapper/centos-home/docker
    

    If these paths don't exist, make sure the filesystem and mountpoints are set up correctly and follow the steps in the previous answer to create the correct paths.

  2. Verify that the permissions for these paths are correct. Normally, Docker needs to have sufficient permissions to read and write to the storage path. You can run the following command to check permissions:

    ls -ld /dev/mapper/centos-home
    ls -ld /dev/mapper/centos-home/docker
    

    Make sure you have the appropriate permissions, usually by making sure the Docker user group (eg dockeror dockerroot) has access to these paths.

  3. If the path exists and the permissions are correct, you can also try to reconfigure Docker to use a different path as the storage path, eg using /var/lib/docker. Edit /etc/docker/daemon.jsonthe file and change "data-root"the value to a different path, then restart the Docker service:

    sudo vi /etc/docker/daemon.json
    # 修改 "data-root" 的值为其他路径,例如 "/var/lib/docker"
    sudo systemctl restart docker
    

After trying the steps above, if the problem persists, it's time to take a closer look at the error messages and logs!

Guess you like

Origin blog.csdn.net/weixin_53742691/article/details/132014937