I am sorry everyone if I misunderstood something
The question in the title is about the “device” in case of a local driver. The following command would show an existing volume’s options:
docker volume inspect test
In case of a simple local volume created without parameters, there is no device. At least not shown in the output. The device would be the first argument of the mount command:
mount <device> <mountpoint>
If we put aside Docker for a moment, a device would be a hard drive for example:
mkdir /mnt/movies
mount /dev/sda1 /mnt/movies
In case of a bind mount, a device is another folder
mkdir /mnt/userhome
mount --bind /home/user /mnt/userhome
If we create a volume without parameters using
docker volume create test
It will create an empty folder at
/var/lib/docker/volumes/test/_data
If I mount it into a non-existent folder inside a container, it remains empty
docker run --rm -it -v test:/app -w /app bash ls -la
If I mount it into an existing folder, the content from the container will be copied to the host
docker run --rm -it -v test:/etc -w /etc bash ls -la
ls -la /var/lib/docker/volumes/test/_data/
Now if I run the mount command instead of “ls”, I can see the mount options and by changing the --opt o=
values I can change those values.
I can also use a simple bind mount without creating a volume and let’s not add any extra like “ro”.
docker volume create readwrite --driver local --opt type=none --opt device=$PWD --opt o=bind
Now I run the following commands and get the same result:
docker run --rm -it -v readwrite:/app -w /app bash mount | grep app
# /dev/sda1 on /app type ext4 (rw,relatime,discard,errors=remount-ro)
docker run --rm -it -v $PWD:/app -w /app bash mount | grep app
# /dev/sda1 on /app type ext4 (rw,relatime,discard,errors=remount-ro)
Running the following commands I also get the same content. The content of the folder that $PWD
refered to when I created to volume.
docker run --rm -it -v readwrite:/app -w /app bash ls -la
docker run --rm -it -v $PWD:/app -w /app bash ls -la
The difference is that the _data
folder is empty. Only a json file is there next to _data
ls -la /var/lib/docker/volumes/readwrite/_data/
# empty folder
cat /var/lib/docker/volumes/readwrite/opts.json
{"MountType":"ext4","MountOpts":"bind","MountDevice":"/home/ubuntu/projects/volumes","Quota":{"Size":0}}
If I want to make the mount readonly, I can
docker volume create readwrite_ro \
--driver local \
--opt type=none \
--opt device=$PWD \
--opt o=bind,ro
docker run --rm -it -v readwrite_remount:/app -w /app bash mount | grep app
/dev/sda1 on /app type ext4 (ro,relatime,discard,errors=remount-ro)
But you are right, I can’t change other options. I guess because the readonly option is supported using the other syntax as well
docker run --rm -it -v $PWD:/app:ro -w /app bash mount | grep app
# dev/sda1 on /app type ext4 (ro,relatime,discard,errors=remount-ro)
In the original question:
I thought the point was to find out how the volume is mounted using which options. I did not consider whether it can be change or not but I indeed assumed that I could change more parameters. In my first post I did not answer the “device” part either which I completely missed.
In my examples it only mounts when I use it as a volume in a container with or without parameters.