GeezerVison is showing github.com — volumes: Implement subpath mount by vvoland · Pull Request #45687 · moby/moby
Conversation
vvoland
commented
Jun 2, 2023
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
- What I did
Make it possible to mount subdirectory of a named volume.
- How I did it
VolumeOptions now has a Subpath field which allows to specify a path relative to the volume that should be mounted as a destination.
Symlinks are supported, but they cannot escape the base volume directory.
A protection against the Time-of-check to Time-of-use is implemented for Linux and Windows to make it not possible to replace the mount source with a symlink that escapes the volume directory.
On Linux, all subpath components are opened with openat, relative to the base volume directory and checked against the volume escape. The final file descriptor is mounted from the /proc/self/fd/ to a temporary mount point owned by the daemon and then passed to the underlying container runtime. Temporary mountpoint is removed after the container is started.
On Windows, all components of the path are locked before the check, and released once the path is already mounted.
- How to verify it
TestRunMountVolumeSubdir integration test
- Description for the changelog
Add Subpath field to the VolumeOptions making it possible to mount a subpath of a volume.
- A picture of a cute animal (not mandatory but encouraged)

Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
PrplHaz4, laurazard, maxnth, sam-thibault, nathancahill, Persaeus, gawdzilla-dev, neumantm, DWolf-19, leotu, and 19 more reacted with hooray emoji
tianon reacted with heart emoji
tianon and nohitme reacted with rocket emoji
All reactions
-
🎉
29 reactions
-
❤️
1 reaction
-
🚀
2 reactions
Uh oh!
There was an error while loading. Please reload this page.
`VolumeOptions` now has a `Subpath` field which allows to specify a path
relative to the volume that should be mounted as a destination.
Symlinks are supported, but they cannot escape the base volume
directory.
Signed-off-by: Paweł Gronowski <[email protected]>
All subpath components are opened with openat, relative to the base
volume directory and checked against the volume escape.
The final file descriptor is mounted from the /proc/self/fd/<fd> to a
temporary mount point owned by the daemon and then passed to the
underlying container runtime.
Temporary mountpoint is removed after the container is started.
Signed-off-by: Paweł Gronowski <[email protected]>
Handle EINTR by retrying the syscall.
Signed-off-by: Paweł Gronowski <[email protected]>
Adapts the function source code to the Moby codebase.
Signed-off-by: Paweł Gronowski <[email protected]>
All components of the path are locked before the check, and
released once the path is already mounted.
This makes it impossible to replace the mounted directory until it's
actually mounted in the container.
Signed-off-by: Paweł Gronowski <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - let's get this one in 🎉
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
PrplHaz4, nbitouze, bobhigs, DWolf-19, Flexusma, Persaeus, FeryET, HumanBojack, jocafi, fuomag9, and jo-chemla reacted with hooray emoji
This was referenced Mar 11, 2024
This was referenced Apr 6, 2024
zmweske
commented
Apr 19, 2024
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
is the long syntax required or would it be possible to utilize short syntax? It currently seems to only work with long syntax but it would make sense to me that if a named volume exists with a subpath, it should work. If a named volume doesn't exist, it will look for folders in ./
See: https://docs.docker.com/compose/compose-file/05-services/#volumes
services:
example:
image: example:latest
volumes:
- named-volume/subpath:/internal/dir:rw # would utilize a named volume that exists in the compose file already
- local-dir/subpath:/internal/dir:rw # would use a local dir as no named volume exists
- ./local-dir2/subpath:/internal/dir2:rw # functionally the same as above
...
volumes:
named-volume:
driver_opts:
type: cifs
o: "uid=1000,username=username,password=${CIFS_PWD},iocharset=utf8,noperm,nobrl,vers=3.0"
device: "//192.168.10.10/example/storage"
Thoughts?
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
This is the wrong issue to discuss Compose's implementation. That being said, we're deliberately avoiding short/ambiguous formats (e.g. the implicit behavior you describe) for new features like this, for (hopefully obvious) reasons of explicit being better than implicit.
Less typing sounds nice, until it leads to a bevy of issue reports, wasted hours debugging, or (in the worst case) security issues.
Please open a discussion on https://github.com/compose-spec/compose-spec for questions, or open an issue if you have a concrete proposal/change to suggest.
|
jo-chemla reacted with thumbs up emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Yeah, I don't think we want to overload the short-form syntax more. Also not sure if such a format should be defined by the compose-spec first (as there's an expectation for the short-form format to be the same as is used for -v short-form).
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Oct 27, 2024
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|