When you use a volume in docker-compose
, docker
will create a volume with the volume name appended to the directory name: [directory containing yml]_[volume name]
/var/containers/my-important-server-v0.23/docker-compose.yml
volumes:
server-db:
# Volume name: my-important-server-v0.23_server-db
Now when you move and rename the directory containing docker-compose.yml
for reasons, it will create a new volume with the new directory prepended to the volume name.
In order to prevent this, and allow multiple compose files to use the same volume, we should have created a volume manually:
docker volume create server-db
volumes:
server-db:
external: true
How can we transfer the files from my-important-server-v0.23_server-db
to server-db
?
This is what I tried and seemed to make sense, but it doesn't work as expected.
docker volume create server-db
OLD=$(docker volume inspect my-important-server-v0.23_server-db | jq -r .[0].Mountpoint)
NEW=$(docker volume inspect server-db | jq -r .[0].Mountpoint)
sudo rsync -va $OLD/ $NEW/
Now here is the problem. The directory containing MariaDB files have different sizes. Apparently you can't simply copy the files like that.