How to safely move /var/lib/docker

Hello.
I have a question.

The /var/lib/docker area has become bloated on centos 7.9 and I want to move it.
After stopping docker,
I ran the following command with rsync.

rsync -aHAXvv --numeric-ids --checksum --delete --devices -S /var/lib/docker/ /home/docker

Checked with diff -r,
I got a message that there is a difference in block special devices such as /home/docker11/overlay2/backingFsBlockDev.

Even after migrating with tar, there is a difference when I look at it with diff.
So I used the dd command to transfer the block special devices, but still there is a difference when I look at it with diff.

Is this a diff problem?
Or is there another way to move the block special device?

Please advise.

The docker engine must be stopped, before the folder is moved, synched or a a tar is created from it.

If the engine is running, you will end up moving files multiple times and destroying the folder structure required for overlay2 to work properly.

The root-data folder can NOT reside on a remote share.

You need to make sure the target ends up using the same storage driver as before. Otherwise, existing images and containers won’t be available, as they are tied to the storage driver.

To be frank: no one actually moves the data-root folder (except it’s on the same host). Instead, we make backups of the content of the docker volumes. Move those backups to the new location, then restore the containers, networks, and volumes from compose files. Then restore the content of the volumes back into the volumes. This way you start with a clean, fresh and reliable setup.

Hello,
Moving your computer stuff is tricky!
You’re trying to move a special folder called “docker” to a new spot. It’s important to do it right, or your computer might get confused.
Let’s figure out how to do it without breaking anything.

1 Like

jason34w
Thanks for the comment.

I ended up moving the container back to an image, extracted the startup options with inspect, and then did a docker save & docker load.