Move Docker Directory to Another Partition

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.

docker_600.jpg

Preparing the Partition

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.

Migrating the Docker Directory to Another 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容器目录迁移


Comments