SoFunction
Updated on 2025-03-09

Solve the problem of too large docker data file causing the root disk to be full

background:

Recently, the docker host used online found that the root directory capacity was almost full. After searching, it was found that the docker data file was too large. We know that docker data is stored in /var/lib/docker by default. We can use the -g --graph="" parameter at startup to change the data directory to other places with large capacity. However, for docker in use, directly modifying this directory path will cause both the image and the container to be lost, so the method of modifying parameters is suitable for use when initializing docker.

For me who want to solve the problem that the root partition is full and does not want to change the data storage path, I do not want to change any docker parameters and data, so I try to migrate this data to a disk with a larger capacity in my virtual machine environment, and then link the data to the original location by linking it to ensure that the environment remains as unchanged as possible.

operate:

1: Close the docker container and docker process:

# /etc//docker stop

2: Migrate data: (Suppose I want to migrate to /mnt/docker)

# mv /var/lib/docker /mnt/

3: Create a directory link

# ln -s /mnt/docker /var/lib/docker
# cd /var/lib
# ll
lrwxrwxrwx 1 root  root   11 Apr 13 10:52 docker -> /mnt/docker

4: Start docker and container:

# /etc//docker start

This experiment was tested to work in my environment. There should be no major problems. If there is anything you overlook, please correct me! I also hope everyone supports me.