Named volume at another location, copied to default location on container startup

Hello all

In my setup, I’ve added a secondary harddisk (/mnt/disk2/) where I would like to store some named volumes.

I use the following command to create a named volume pointing to some folder there:

docker volume create --name jenkins-home --opt type=none --opt device=/mnt/disk2/docker-volumes/jenkins-home --opt o=bind

which seems to work so far.

Now what irritates me is that when I start the correpsonding container, all the data from /mnt/disk2/docker-volumes/jenkins-home is then also visible in /var/lib/docker/volumes/jenkins-home/_data. Are all data copied there upon startup of the container? Also as soon as I stop the container, the folder /var/lib/docker/volumes/jenkins-home/ is emptied.
I also did some tests: When I modify/add something in any directory, it is immediately visible in the other directory as well. That sounds like a symlink but it does not show the _data folder as symlink to /mnt/disk2/docker-volumes/jenkins-home.

So how does it work then? Is really all data copied to the original volumes folder and some kind of sync running all the time? Or is there some other magic? If the data is just copied, I need to find another way to have the volumes on the second disk as the first one is too small. Also I do want to use named volumes so I can easily do backups with --volumes-from.

Thanks for your information and help
Roman

Run the command du -d1 --one-file-system /var/lib/docker/volumes/jenkins-home/ with and withouth “–one-file-system” and see what happens if you stay within your main drive and what happens if the mounted drive is put into the calculation as well. Check the output of mount | grep /var/lib/docker/volumes/jenkins-home/_data and see that your “–opt --device” path is actualy mounted into /var/lib/docker/volumes/jenkins-home/_data. Technicaly, this is a mount --bind.

1 Like