I have a docker installation with several images and about 150Gigs of data in /var/lib/docker
. This setup uses overlayfs
as its storage driver. There are several directories for each layer under /var/lib/docker/overlay
holding the actual data. The partition size is 160G.
My requirement is to copy the the docker directory from /var/lib/docker
to a new disk of 1TB, so that I point docker to start from this new partition and continue to use my old images.
Now the problem is, when I use an rsync
or a cp
command with -a
, to copy /var/lib/docker
to new partition, instead of a total of 150G actual data, the total copied data is coming to as much as 600G (and counting..).
Docker is stopped as well, but not sure how OS is looking at the 160G data and copying into 600G+. I hope it is not the overlayfs (merged directories). There is no overlay information on df -aTh
. Nor did it help unloading kernel overlayfs driver with rmmod overlay
How is it possible that I could just copy this data as-is, without any expansion/merge taking place.
The /var/lib/docker/aufs directory points to three other directories: diff, layers and mnt. Image layers and their contents are stored in the diff directory.
OverlayFS is a modern union filesystem that is similar to AUFS, but faster and with a simpler implementation. Docker provides two storage drivers for OverlayFS: the original overlay , and the newer and more stable overlay2 .
Overlay filesystems (also called union filesystems) is a fundamental technology in Docker to create images and containers. They allow creating a union of directories to create a filesystem. Multiple filesystems, which are just directories, are superposed one on top of another to create a new filesystem.
It turned out that docker is using hardlinks
within those directories under /var/lib/docker/overlay
. Using -H
with rsync (copy hardlinks as hardlinks) solved the issue.
rsync -avPHSX /var/lib/docker /new/partition/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With