Publish: 2020-09-07 | Modify: 2020-09-07
After installing Docker, the default directory is /var/lib/docker
. If this directory is not separately partitioned, it will occupy space in the root partition. If the root partition is full, it will affect the normal use of the server. Therefore, it is necessary to migrate the Docker directory to a non-root partition directory.
If you are ready to run Docker, you can plan the partition in advance and mount /var/lib/docker
to a separate partition to avoid occupying the root partition.
If your Docker is already running and you forgot to plan the partition, you will need to migrate the data. First, stop the Docker service:
systemctl stop docker
Backup the files:
mv /var/lib/docker /var/lib/docker_bak
Move the files to another partition. Here, we have already created a new partition /home/disk2
, and we will migrate the data to this partition:
cd /home/disk2
cp -a /var/lib/docker_bak docker
Create a symbolic link:
ln -s /home/disk2/docker /var/lib/docker
Finally, restart the Docker service:
systemctl start docker
After testing without any issues, you can delete the backup directory /var/lib/docker_bak
.
This article refers to: Docker容器目录迁移
I come from China and I am a freelancer. I specialize in Linux operations, PHP, Golang, and front-end development. I have developed open-source projects such as Zdir, ImgURL, CCAA, and OneNav.