Remove restriction on anonymous read-only volumes#51682
Conversation
185e372 to
15f622a
Compare
|
Did a quick check if the read-only would potentially cause issues when propagating the content; Created an image with content existing at the destination; docker build -t foo -<<'EOF'
FROM alpine
RUN mkdir -p /data/dest && echo "hello" > /data/dest/file.txt
EOFdocker run --rm --mount type=volume,dst=/data/dest,readonly -w /data/dest foo sh -c 'ls -l && echo "foo" > new-file.txt'
total 4
-rw-r--r-- 1 root root 6 Dec 11 11:20 file.txt
sh: can't create new-file.txt: Read-only file systemAlso checking docker run -dit --rm --name container1 --mount type=volume,dst=/data/dest,readonly -w /data/dest foo
docker run -it --volumes-from container1 -w /data/dest alpine sh -c 'ls -l && echo "foo" > new-file.txt'
total 4
-rw-r--r-- 1 root root 6 Dec 11 11:20 file.txt
sh: can't create new-file.txt: Read-only file systemThere's one issue we should look at, and whether we want to support or not; the shorthand docker run -it --rm -v /data/dest:ro -w /data/dest foo
docker: Error response from daemon: invalid volume specification: '/data/dest:ro'When specifying a source ( docker run -it --rm -v myvolume:/data/dest:ro -w /data/dest fooIn general, it's OK for the advanced ( That said; I guess that's already the case for other options, like SELinux labels ( docker run --rm -v myvolume:/data/dest:z -w /data/dest foo
docker run --rm -v data/dest:z -w /data/dest foo
docker: Error response from daemon: invalid volume specification: 'data/dest:nocopy' |
15f622a to
9c1ac82
Compare
|
We should add some tests for this though before merging; let me know if you need help with that/ |
20d7b46 to
719ed69
Compare
|
Took a stab at some simple tests, adding |
|
CI failure: |
|
@vvoland Really sorry if I'm just missing it (still getting used to the CI/test setup) but is there a chance that failure is from a previous version of the PR? I can't find that failure in the most recent results, and the test passes locally for me in the dev container: At one point I had used a and if I add that back it fails with the |
719ed69 to
78d1637
Compare
|
I gave CI a kick to run |
|
One failure; looks like it may be related; |
Restriction on anonymouse read-only volumes is currently preventing the use of pre-populated volumes that should be accessed in a read-only manner in a container (e.g. an NFS volume containing data to be processed or served). According to @neersighted the restriction may have originally been put in place with the assumption that pre-populated volumes would be exposed as a named volume by the volume driver. In practice, NFS volumes are mounted using the docker `local` driver by supplying driver opts. Example that fails when `readonly` is specified but works without: ``` docker run --rm -it \ --mount 'readonly,type=volume,dst=/data/dest,volume-driver=local,volume-opt=type=nfs,volume-opt=device=:/export/some-share,"volume-opt=o=nfsvers=4,addr=some.server"' \ debian ``` Fixes moby#45297 Signed-off-by: Shane St Savage <shane@axds.co>
78d1637 to
beeacde
Compare
|
Thanks very much for the review and suggestions. I applied all of them, confirmed that tests pass locally for me as well, rebased against master, and pushed the changes. 🤞 on CI passing this time... |
|
Seems like |
The test was failing on Windows because it used Unix-style paths and relied on platform-specific filesystem behavior. Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
184c252 to
1175dd3
Compare
|
I've adjusted the tests (one is skipped on Windows). It's a bit of a workaround, because the parser itself shouldn't care if the source directory exists or not... but it's unrelated to this change so let's not try to fix it here. |
vvoland
left a comment
There was a problem hiding this comment.
LGTM, but since I pushed one commit, I would appreciate a second review 😅
Remove restriction on anonymous read-only volumes.
This restriction is currently preventing the use of pre-populated volumes that should be accessed in a read-only manner in a container (e.g. an NFS volume containing data to be processed or served).
According to @neersighted the restriction may have originally been put in place with the assumption that pre-populated volumes would be exposed as a named volume by the volume driver.
In practice, NFS volumes are mounted using the docker
localdriver by supplying driver opts. Example that fails whenreadonlyis specified but works without:Fixes #45297
- What I did
Removed restriction on anonymous read-only volumes.
- How I did it
Deleted simple checks for anonymous read-only volumes from Linux and Windows volume parsers.
- How to verify it
After changes, read only mount an NFS share using something like
- Human readable description for the release notes