Background

We've run into a few cases where filling the default /var/lib/docker directory on the root partition has caused failures.  The best solution is to mount an external volume on either /var/lib/docker or use the Docker daemon -g flag to specify a different location.  However, if you have a full disk and want to preserve the /var/lib/docker directory, the solution isn't obvious.

Solution

As noted in  NDS-996 - Getting issue details... STATUS , by default on CoreOS systems Docker uses overlayfs.  Overlayfs uses hard links to reduce storage space.  A simple "mv" or "cp" across filesystem boundaries will result in a target directory that is much larger than the original.  The solution in this case is to use rsync:

systemctl stop docker
rsync -aHSX /var/lib/docker /mnt/docker
mount --bind /mnt/docker /var/lib/docker
systemctl start docker

There are multiple benefits to rsync – restartable, permissions and extended attributes can be preserved, in addition to the -H flag preserving hard links.


See also

  • No labels