GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — volumes: Implement subpath mount by vvoland · Pull Request #45687 · moby/moby

Conversation

@vvoland

@vvoland vvoland commented Jun 2, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor
  • Depends on: contrib/busybox: Update to FRP-5007-g82accfc19 #45784

  • Fixes [feature] Allow mounting sub-directories of named volumes #32582

  • Supersedes, closes Allow mounting a sub-directory of a named volume #39041

- 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)
image

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
@vvoland vvoland added area/api API kind/feature Functionality or other elements that the project doesn't currently have. Features are new and shiny impact/changelog area/volumes Volumes labels Jun 2, 2023
@vvoland vvoland added this to the 25.0.0 milestone Jun 2, 2023
@vvoland vvoland added the status/1-design-review label Jun 2, 2023
@vvoland
vvoland force-pushed the volume-mount-subpath branch 6 times, most recently from 162300a to e346dc5 Compare June 2, 2023 13:54
vvoland
vvoland commented Jun 2, 2023
View reviewed changes
Comment thread volume/mounts/mounts.go Resolved

Uh oh!

There was an error while loading. Please reload this page.

@vvoland
vvoland force-pushed the volume-mount-subpath branch 2 times, most recently from 0176b5a to 1765550 Compare June 2, 2023 15:48
@vvoland vvoland mentioned this pull request Jun 2, 2023
mount: Add volume-subpath option docker/cli#4331
Merged
@vvoland
vvoland force-pushed the volume-mount-subpath branch 14 times, most recently from b301fa1 to ac302cb Compare June 7, 2023 15:57
vvoland added 9 commits January 19, 2024 17:32
@vvoland
volumes: Implement subpath mount
bfb8104
`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]>
@vvoland
internal/safepath: Add linux implementation
9a0cde6
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]>
@vvoland
internal/safepath: Handle EINTR in unix syscalls
3784316
Handle EINTR by retrying the syscall.

Signed-off-by: Paweł Gronowski <[email protected]>
@vvoland
internal/safepath: Import k8s safeopen function
56bb143
For use as a soft fallback if Openat2 is not available.
Source: https://github.com/kubernetes/kubernetes/blob/55fb1805a1217b91b36fa8fe8f2bf3a28af2454d/pkg/volume/util/subpath/subpath_linux.go

Signed-off-by: Paweł Gronowski <[email protected]>
@vvoland
internal/safepath: Adapt k8s openat2 fallback
5841ed4
Adapts the function source code to the Moby codebase.

Signed-off-by: Paweł Gronowski <[email protected]>
@vvoland
internal/safepath: Add windows implementation
42afac9
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]>
@vvoland
container: Change comment into debug log
349a52b
Signed-off-by: Paweł Gronowski <[email protected]>
@vvoland
daemon/populateVolumes: Support volume subpath
cb1af22
Signed-off-by: Paweł Gronowski <[email protected]>
@vvoland
volumes/subpath: Plumb context
5bbcc41
Signed-off-by: Paweł Gronowski <[email protected]>
thaJeztah
thaJeztah approved these changes Jan 19, 2024
View reviewed changes

@thaJeztah thaJeztah left a comment

Copy link
Copy Markdown
Member

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
All reactions
  • 🎉 11 reactions
@Johnny-Knighten Johnny-Knighten mentioned this pull request Jan 31, 2024
Manual_config doesn't seems to work, and reset the configFile Johnny-Knighten/palworld-server#11
Closed
This was referenced Mar 11, 2024
Add volume subpath property compose-spec/compose-spec#471
Merged
Add support for volume Subpath option docker/compose#11597
Closed
@felipecrs felipecrs mentioned this pull request Mar 20, 2024
Investigate support for subpath mounts on Docker 26+ felipecrs/docker-on-docker-proxy#11
Closed
This was referenced Apr 6, 2024
Support subpath paths for -v or --mount podman-container-tools/podman#20661
Closed
Add missing user-facing part to allow volume subpath mounts podman-container-tools/podman#22040
Closed
@jocafi jocafi mentioned this pull request Apr 6, 2024
docker compose fails to mount sub-directories of named volumes #47687
Closed
@zmweske

zmweske commented Apr 19, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

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?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@neersighted

neersighted commented Apr 20, 2024

Copy link
Copy Markdown
Member

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
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thaJeztah

thaJeztah commented Apr 22, 2024

Copy link
Copy Markdown
Member

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).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pauliuspetk pauliuspetk mentioned this pull request Apr 25, 2024
Support for VolumeOptions.Subpath in docker_container.mounts.volume_options kreuzwerker/terraform-provider-docker#612
Closed
@dazinator dazinator mentioned this pull request May 17, 2024
New volume mount subpath - does not create sub directory if it doesn't ee #47842
Open
@Khushiyant Khushiyant mentioned this pull request Jun 10, 2024
Mount of volume-subpath which is available in Docker version 26.0.0, build 2ae903e using Python SDK for docker docker/docker-py#3243
Closed
@kieraneglin kieraneglin mentioned this pull request Aug 3, 2024
[FR] A different download directory per media profile, or per source kieraneglin/pinchflat#337
Closed
@thaJeztah thaJeztah mentioned this pull request Aug 12, 2024
engine: volume subpath mount docker/docs#20577
Merged
@stivyw stivyw mentioned this pull request Aug 21, 2024
Compose volume subpath: option fails with invalid mode docker/desktop-linux#222
Open
@Khushiyant Khushiyant mentioned this pull request Sep 17, 2024
Implement Subpath Support for Volumes in Docker-Py (#3243) docker/docker-py#3270
Merged
This was referenced Oct 27, 2024
internal/safepath: log some unhandled errors, and remove workaround for ECI / Sysbox #48774
Merged
Implement mount from image #48798
Merged
@jarneson-bplus jarneson-bplus mentioned this pull request May 16, 2025
Named volume subpath being silently ignored portainer/portainer#12692
Closed
2 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@neersighted neersighted neersighted approved these changes
@rumpl rumpl rumpl approved these changes
@corhere corhere corhere approved these changes
@cpuguy83 cpuguy83 cpuguy83 approved these changes
@thaJeztah thaJeztah thaJeztah approved these changes
@akerouanton akerouanton Awaiting requested review from akerouanton
@laurazard laurazard Awaiting requested review from laurazard

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@vvoland vvoland

Labels

area/api API area/volumes Volumes impact/changelog kind/feature Functionality or other elements that the project doesn't currently have. Features are new and shiny status/1-design-review

Projects

None yet

Milestone

26.0.0

Development

Successfully merging this pull request may close these issues.

[feature] Allow mounting sub-directories of named volumes

Uh oh!

There was an error while loading. Please reload this page.

9 participants

@vvoland @thaJeztah @cpuguy83 @nathancahill @zmweske @neersighted @rumpl @corhere @laurazard
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.