Home >Operation and Maintenance >Docker >What to do if docker storage space is insufficient

What to do if docker storage space is insufficient

WBOY
WBOYOriginal
2022-07-22 15:44:1014709browse

Solution: 1. After stopping the docker service, use "rsync -avz /var/lib/docker large disk directory/docker/lib/" to migrate docker to a large-capacity disk; 2. Edit "/ etc/docker/daemon.json" to add specified parameters to migrate and bind the docker directory; 3. Reload and restart the docker service.

What to do if docker storage space is insufficient

The operating environment of this tutorial: linux7.3 system, docker version 19.03, Dell G3 computer.

What to do if docker storage space is insufficient

When we use docker, we often create new images and new containers, and install various packages in the new containers. These things are not virtual. Instead, it actually exists in our disk. By default, it is in /var/lib/docker. This directory belongs to the system disk, and the space of the system disk is often not large. This will cause, over time, Docker is getting bigger and bigger, and finally the system disk space is full, so at this time, it is necessary to migrate the docker storage directory to a larger disk to free up the system disk space.

Check the usage of all disks on the server:

df -h

You can see that the red box is the size of the system disk. The total size is 188G (much smaller than other disks). The previous It’s full, but the blogger has already done the migration, so there’s a lot of space left.

What to do if docker storage space is insufficient

Check the space size of the docker image and container storage directory

du -sh /var/lib/docker/

Stop the docker service

systemctl stop docker

The strange thing here is that my systemctl keeps failing and the reason cannot be found. The error is reported as follows:

Failed to execute operation: Launch helper exited with unknown return code 1

Anyone who knows the reason can teach me how to solve it. If you try the above command and fail, use the following command:

service docker stop

Solution:

1. Migrate docker to a large-capacity disk

# 首先创建目录
mkdir -p 大磁盘目录/docker/lib/
# 迁移
rsync -avz /var/lib/docker 大磁盘目录/docker/lib/

2. Edit /etc/docker/daemon.json, add parameters, and bind the docker directory migration

The red box is the added parameter

What to do if docker storage space is insufficient

##3. Reload and restart the docker service

systemctl daemon-reload && systemctl restart docker

But I still failed to run systemctl , so I used the following command to restart docker:

service docker restart

Check whether docker is bound to the new directory

docker info

If the Docker Root Dir changes from /var/lib/docker to the directory you specify, Indicates that the migration is successful.

What to do if docker storage space is insufficient

Delete old docker directory

rm -rf /var/lib/docker

Recommended study: "

docker video tutorial"

The above is the detailed content of What to do if docker storage space is insufficient. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn