Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support subpath paths for -v or --mount #20661

Closed
larsks opened this issue Nov 12, 2023 · 7 comments · Fixed by #24532
Closed

Support subpath paths for -v or --mount #20661

larsks opened this issue Nov 12, 2023 · 7 comments · Fixed by #24532
Labels
kind/feature Categorizes issue or PR as related to a new feature.

Comments

@larsks
Copy link
Contributor

larsks commented Nov 12, 2023

Feature request description

I'm glad that support for subpath mounts in pod manifests was added in #16803. I'd like to see the same capability exposed via podman run, either by extending the syntax of --volume, so that we can write:

podman run -v somevolume/internal/path:/container/path ...

Or by adding an additional subpath keyword to --mount, so that we can write:

podman run --mount type=volume,subpath=internal/path,destination=/container/path

Suggest potential solution

I think the reasons for wanting to do this are covered in #12929. I just want to be able to do it from the command line because in many situations a simple podman run ... invocation is both faster and more effective than setting up a pod manifest.

I think adding the subpath keyword to --mount would be the cleanest and least disruptive way of implementing this feature.

Have you considered any alternatives?

While it's possible to do this using a pod manifest, the behavior of podman kube play is different from the behavior of podman run; in particular, it's not really designed for running a container interactively from the command line.

Additional context

Add any other context or screenshots about the feature request here.

@larsks larsks added the kind/feature Categorizes issue or PR as related to a new feature. label Nov 12, 2023
@rhatdan
Copy link
Member

rhatdan commented Nov 12, 2023

The trend is to require the use of --mount rather then --volume, for ultimate flexibility and this seems reasonable.
WDYT @vrothberg @mheon ?

@mheon
Copy link
Member

mheon commented Nov 12, 2023 via email

@giuseppe
Copy link
Member

yes, it was not implemented safely originally. If we open the mount first as we already do for the kube path, then it is safe as another container cannot create a malicious symlink to escape it.

@larsks
Copy link
Contributor Author

larsks commented Apr 6, 2024

It looks like Docker has just added this feature in v26.0.0; there is now a volume-subpath mount option:

docker run -it --rm \
  --mount type=volume,source=vol-web,target=/data,volume-subpath=pgdata \
  alpine sh

@cyqsimon
Copy link

cyqsimon commented Jun 11, 2024

Ran head first into this today.

My compose.yml declares several containers that share a volume but are supposed to be mounted on distinct subpaths. But I was surprised to see that when I brought up the containers using podman compose (delegates to docker-compose), the subpath key is SILENTLY ignored and all files went into the volume root, which is BAD. I was lucky not to have run into any file conflicts.

I think this is another important concern to address, because if it's implemented without special attention to and handling of backward compatibility, the effective file layout within the volume will become inconsistent with actual data. As a consequence of this, at best, users of compose files may find their data "gone" after an update (because it now mounts an empty subpath); and at worst, the container may overwrite existing files at incorrect locations, causing a data corruption.

Please correct me if I'm wrong (and I really hope I'm wrong), but I don't think there is a way to retroactively sort existing data (which is often a mixed blend of data from multiple containers) into subpaths cleanly. So I suppose this would have to be a breaking change with the appropriate warnings put in place.

@gilesknap
Copy link

I have the same issue as @cyqsimon. I'm building a framework that I want podman and docker users to be able to make use of.

My compose files work beautifully in both except that subpath is silently ignored when using podman.

I don't have a good workaround to this. I'll probably have to create multiple volumes and then somehow track them all in the consumer.

@gilesknap
Copy link

Re the breaking change point. For me there are file name clashes so I'm already broken in podman.

If that were not the case then I may never have noticed the discrepancy and would be prone to data loss if podman is updated to support sub path.

Therefore I suggest a config option to enable the feature, defaulting to 'legacy', i.e. ignore sub-path in compose.yml.

gilesknap added a commit to gilesknap/bl01t that referenced this issue Jun 30, 2024
as a workaround to podman's inability to use sub_path volume
mounts

see containers/podman#20661
mheon added a commit to mheon/libpod that referenced this issue Nov 11, 2024
All the backend work was done a while back for image volumes, so
this is effectively just plumbing the option in for volumes in
the parser logic. It's a little uglier than I'd like because
our volume mount parser produces an OCI Spec mount struct, which
doesn't have a field for subpath, so we have to pass through the
options array and parse it back out after, which is a little
gross. But not gross enough to rewrite that parsing logic.

Fixes containers#20661

Signed-off-by: Matt Heon <[email protected]>
mheon added a commit to mheon/libpod that referenced this issue Nov 11, 2024
All the backend work was done a while back for image volumes, so
this is effectively just plumbing the option in for volumes in
the parser logic. It's a little uglier than I'd like because
our volume mount parser produces an OCI Spec mount struct, which
doesn't have a field for subpath, so we have to pass through the
options array and parse it back out after, which is a little
gross. But not gross enough to rewrite that parsing logic.

Fixes containers#20661

Signed-off-by: Matt Heon <[email protected]>
mheon added a commit to mheon/libpod that referenced this issue Nov 11, 2024
All the backend work was done a while back for image volumes, so
this is effectively just plumbing the option in for volumes in
the parser logic. It's a little uglier than I'd like because
our volume mount parser produces an OCI Spec mount struct, which
doesn't have a field for subpath, so we have to pass through the
options array and parse it back out after, which is a little
gross. But not gross enough to rewrite that parsing logic.

Fixes containers#20661

Signed-off-by: Matt Heon <[email protected]>
mheon added a commit to mheon/libpod that referenced this issue Nov 12, 2024
All the backend work was done a while back for image volumes, so
this is effectively just plumbing the option in for volumes in
the parser logic. We do need to change the return type of the
volume parser as it only worked on spec.Mount before (which does
not have subpath support, so we'd have to pass it as an option
and parse it again) but that is cleaner than the alternative.

Fixes containers#20661

Signed-off-by: Matt Heon <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants