preface

Docker server, after running for a period of time, found that the server disk directory is almost insufficient. Du -h –max-depth=1 / indicates that the /var/lib/docker directory is too large. To solve the problem, perform the following steps:

Transfer data changes the default docker storage location

There are several ways to change the default docker storage location. It is best to modify the default storage location of Docker to other large directories or disks in the first time after docker is installed. Avoid risks caused during data migration.

  • Stop the Docker service
    systemctl stop docker
    Copy the code
  • To create a new docker directory, run df -h to find a large disk

    I created /home/modules/ docker-lib under /home
     mkdir -p /home/modules/docker/lib
    Copy the code
  • Migrate files under /var/lib/docker to /home/modules/docker-lib

    The migrated to complete the docker path: / home/modules/docker/lib/docker
    rsync -avz /var/lib/docker/ /home/modules/docker/lib/
    Copy the code
  • Configure the/etc/systemd/system/docker. Service. D/devicemapper. Conf

    Check the/etc/systemd/system/docker. Service. D directory and the devicemapper. Conf exists. If it does not exist, create one
    mkdir -p /etc/systemd/system/docker.service.d/
    vi /etc/systemd/system/docker.service.d/devicemapper.conf
    Copy the code

    Add the following to devicemapper.conf:

    [Service]
    ExecStart=
    ExecStart=/usr/bin/dockerd  --graph=/home/modules/docker/lib/docker
    Copy the code
  • Restart the docker
    systemctl daemon-reload
    systemctl restart docker
    systemctl enable docker
    Copy the code
  • Check whether the Docker Root Dir modification has taken effect
    [root@iZbp1jcwx7sfb1yrnvpg84Z docker]# docker info. Docker Root Dir: /home/modules/docker/lib/docker Debug Mode (client):false
    Debug Mode (server): false
    Registry: https://index.docker.io/v1/
    ...
    Copy the code
  • After the startup is successful, check whether the previous image is still available
    [root@iZbp1jcwx7sfb1yrnvpg84Z docker]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZE 10.80.177.233/ Policy 2.1.2 64AC4e178cd2        2 hours ago         818 MB
    10.80.177.233/crm                   2.1.3               d7636fbb7a29        2 hours ago         762 MB
    Copy the code
  • Delete the files in the /var/lib/docker-/ directory

Reference link: blog.csdn.net/weixin_3282…