Docker data directory migration method


foreword

For the docker service installed on the server, the data is stored in the /var/lib/docker directory by default. Since this directory is on the system disk, as time goes by, docker takes up more and more space, and the system disk is the most crowded. 1G, it is easy to 100% of the disk, thinking about migrating the directory occupied by docker to a non-system disk directory, do it immediately when you think about it

insert image description here


1. Stop the Docker service?

systemctl stop docker

2. Migrate docker data to the data catalog

rsync -r -avz /var/lib/docker /data/docker/lib/

3. Back up the original data directory

mv /var/lib/docker /var/lib/docker.old

4. Add a soft link

ln -s /data/docker/lib/docker /var/lib/

5. Restart the docker service

systemctl start docker

After starting Docker, the path written by Docker is still /var/lib/docker, but because of the soft link setting, it is actually written to a new directory. So far, the migration of the Docker data directory has been completed.

6. After confirming that there is no problem with the service, delete the backup directory

rm -rf /var/lib/docker.old

Summarize

After the Docker data directory is successfully migrated, there is no need to worry about the server system disk directory being full

Guess you like

Origin blog.csdn.net/itopit/article/details/130798569