Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy /var/lib/docker with overlayfs directory structure with data *as-is* without increasing the storage space

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.

like image 374
VanagaS Avatar asked Sep 23 '16 20:09

VanagaS


People also ask

What are the 3 different directories in var lib docker AUFS?

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.

Does docker use OverlayFS?

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 .

What is docker overlay directory?

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.


1 Answers

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/
like image 181
VanagaS Avatar answered Oct 05 '22 05:10

VanagaS