I had a large Docker Compose project on a Proxmox LXC and I recently decided to migrate that to a new VM. So, in addition to code, I had to create an exact copy of my Docker volume and non-volume data. Here’s how I did that.
First, a few things to note:
- I used the destination VM to trigger the
rsynccommand. - I used
sudoon both sides because the files were owned by multiple arbitrary users. (This complicated things a bit.) - I had to do the following in order. (Earlier, I didn’t
docker compose createand ran into this error.)rsyncthe Docker Compose code.docker compose createon the destination.rsyncDocker volume data. (I did this twice actually: once, while the project wasupon the source and once after bringing itdown. This helped me decrease overall downtime.)docker compose up -dor whatever on the destination.
Second, I used something like the following to create exact copies:
sudo rsync \
-e "ssh -i /home/arch/.ssh/id_ed25519" \
-aPHAX \
--numeric-ids \
--delete \
--rsync-path="sudo /usr/bin/rsync" \
--exclude='docker_foo/***' \
--include='docker_*/***' \
--exclude='*' \
user@src_host:/var/lib/docker/volumes/ /var/lib/docker/volumes/
Here, the ordering of --exclude and --include was important.