Move Docker Volumes using rsync

published on in category Docker , Tags: docker linux rsync

I’m running a Docker host on a Hetzner Cloud server. Since my GitLab instance grew quite big, I bought some additional storage that’s mounted to the machine as a additional device. All my Docker stuff uses local volumes located in /var/lib/docker/volumes. The question now was: How to move those volumes to the new storage? Docker volumes are basically just subdirectories in a special folder. For some applications it’s important to copy over all the extended attributes and other metadata like permissions, ownership and change dates.

First off, I logged in as root, stopped the Docker daemon using systemctl stop docker. Then I copied /var/lib/docker/volumes to /var/lib/docker/_volumes, mounted the new block storage to the original volumes location and added it to /etc/fstab.

Then, it’s easy to copy over all the volume data. I started a tmux session and copied over all the files like this:

rsync -avX --progress /var/lib/docker/_volumes/ /var/lib/docker/volumes/

Afterwards, just start Docker again using systemctl start docker.

I run this site without advertisement of any kind. All information is free and my only goal is to give back something to the amazing free software development community. If you find some value in this, please consider donating me a cup of coffee using PayPal. Thank you so much!