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

Add support for anonymous volumes to podman run -v #4287

Merged
merged 1 commit into from
Oct 22, 2019

Conversation

mheon
Copy link
Member

@mheon mheon commented Oct 17, 2019

Previously, when podman run encountered a volume mount without separate source and destination (e.g. -v /run) we would assume that both were the same - a bind mount of /run on the host to /run in the container. However, this does not match Docker's behavior - in Docker, this makes an anonymous named volume that will be mounted at /run.

We already have (more limited) support for these anonymous volumes in the form of image volumes. Extend this support to allow it to be used with user-created volumes coming in from the -v flag.

This change also affects how named volumes created by the container but given names are treated by podman run --rm and podman rm -v. Previously, they would be removed with the container in these cases, but this did not match Docker's behaviour. Docker only removed anonymous volumes. With this patch we move to that model as well; podman run -v testvol:/test will not have testvol survive the container being removed by podman rm -v.

The sum total of these changes let us turn on volume removal in --rm by default.

Fixes: #4276

@openshift-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mheon

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/M labels Oct 17, 2019
@mheon
Copy link
Member Author

mheon commented Oct 17, 2019

Needs tests and manpage adjustments still. Will hit those after lunch.

@mheon mheon force-pushed the anonymous_volumes branch 2 times, most recently from 7a1f71d to 86b57a7 Compare October 17, 2019 17:04
@mheon
Copy link
Member Author

mheon commented Oct 17, 2019

Docs done, test added. Want to add a few more around removing containers with -v and volumes being retained / not being retained.

Previously, when `podman run` encountered a volume mount without
separate source and destination (e.g. `-v /run`) we would assume
that both were the same - a bind mount of `/run` on the host to
`/run` in the container. However, this does not match Docker's
behavior - in Docker, this makes an anonymous named volume that
will be mounted at `/run`.

We already have (more limited) support for these anonymous
volumes in the form of image volumes. Extend this support to
allow it to be used with user-created volumes coming in from the
`-v` flag.

This change also affects how named volumes created by the
container but given names are treated by `podman run --rm` and
`podman rm -v`. Previously, they would be removed with the
container in these cases, but this did not match Docker's
behaviour. Docker only removed anonymous volumes. With this patch
we move to that model as well; `podman run -v testvol:/test` will
not have `testvol` survive the container being removed by `podman
rm -v`.

The sum total of these changes let us turn on volume removal in
`--rm` by default.

Fixes: containers#4276

Signed-off-by: Matthew Heon <[email protected]>
@mheon mheon force-pushed the anonymous_volumes branch from 86b57a7 to 0d62391 Compare October 17, 2019 17:18
@mheon
Copy link
Member Author

mheon commented Oct 17, 2019

Alright, tests are all done. I think this is ready.

@mheon
Copy link
Member Author

mheon commented Oct 18, 2019

@@ -437,7 +437,7 @@ func (r *LocalRuntime) Run(ctx context.Context, c *cliconfig.RunValues, exitCode
}

if c.IsSet("rm") {
if err := r.Runtime.RemoveContainer(ctx, ctr, false, false); err != nil {
if err := r.Runtime.RemoveContainer(ctx, ctr, false, true); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the volume from this container is shared with another container?

@rhatdan
Copy link
Member

rhatdan commented Oct 19, 2019

Everything looks good, but I am wondering about the force removal of volumes.

@mheon
Copy link
Member Author

mheon commented Oct 19, 2019 via email

@rhatdan
Copy link
Member

rhatdan commented Oct 20, 2019

LGTM

@baude
Copy link
Member

baude commented Oct 22, 2019

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 22, 2019
@openshift-merge-robot openshift-merge-robot merged commit d358840 into containers:master Oct 22, 2019
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 26, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Anonymous volume is incompatible with Docker
5 participants