Home >Operation and Maintenance >Docker >What to do if docker storage space is insufficient
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.
The operating environment of this tutorial: linux7.3 system, docker version 19.03, Dell G3 computer.
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.
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
##3. Reload and restart the docker service
systemctl daemon-reload && systemctl restart dockerBut I still failed to run systemctl , so I used the following command to restart docker:
service docker restartCheck whether docker is bound to the new directory
docker infoIf the Docker Root Dir changes from /var/lib/docker to the directory you specify, Indicates that the migration is successful. Delete old docker directory
rm -rf /var/lib/dockerRecommended 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!