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

On container rm, don't remove named mountpoints #19568

Merged
merged 1 commit into from Jan 26, 2016

Conversation

cpuguy83
Copy link
Member

This makes it so when calling docker run --rm, or docker rm -v, only
volumes specified without a name, e.g. docker run -v /foo instead of
docker run -v awesome:/foo are removed.

Note that all volumes are named, some are named by the user, some get a
generated name. This is specifically about how the volume was specified
on run, assuming that if the user specified it with a name they expect
it to persist after the container is cleaned up.

Fixes #17907

dockerCmd(c, "run", "--rm", "-v", "test:/foo", "-v", "/bar", "busybox", "true")
dockerCmd(c, "volume", "inspect", "test")
out, _ := dockerCmd(c, "volume", "ls", "-q")
c.Assert(strings.TrimSpace(out), checker.Equals, "test")
Copy link
Contributor

Choose a reason for hiding this comment

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

can we assert that bar is not in the output too somehow?

Copy link
Member Author

Choose a reason for hiding this comment

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

We are, we are doing checker.Equals

Copy link
Contributor

Choose a reason for hiding this comment

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

oh right, nevermind, thanks.

@calavera
Copy link
Contributor

sounds like a great plan 👍

@thaJeztah
Copy link
Member

nice approach for this! basically, this would handle the cases below;

docker run --rm myname:/foo ...

# note: no name specified during creation of the volume
# however, the generated name is passed on to docker run
# so it's considered a "named" volume, and won't be removed
VOL=$(docker volume create); docker run --rm -v $VOL:/foo ..

# same here, but no intermediate variable
docker run --rm -v $(docker volume create):/foo ...

In all those cases, the volume is not removed when the container is removed. However, the examples below treat the volume as ephemeral and remove the volume together with the container;

docker run --rm -v /foo ..

# image that has a `VOLUME` specified;
docker run --rm something

@thaJeztah
Copy link
Member

We may need to update some documentation explaining this

@cpuguy83
Copy link
Member Author

@thaJeztah I'll take a look at the docs tomorrow.

@thaJeztah
Copy link
Member

@cpuguy83 👍 just mentioning it to prevent trigger-happy merges 😄

@coolljt0725
Copy link
Contributor

@cpuguy83 I tested your branch. This scenario does not work, the volume still be remove if the named volume is from --volumes-from CONTAINER and the original CONTAINER has been removed.


$ docker volume create --name data
data
$ docker run -ti --name foo -v data:/data busybox
/ # exit
$ docker run -ti --rm --name bar --volumes-from foo busybox
/ #

Remove container foo
$ docker rm foo foo
And then kill container bar, the volume data will be removed

DEBU[0637] DELETE /v1.23/containers/7b4e2b232d6269036b1bf28f9b563426b0b7cac60e0125446d420a6eaca45e6e?v=1
DEBU[0637] Removing volume reference: driver local, name data

seems we should also handle https://github.com/docker/docker/blob/master/daemon/volumes.go#L73

@cpuguy83
Copy link
Member Author

@coolljt0725 Nice catch! Updated with a fix and another test.

@estesp
Copy link
Contributor

estesp commented Jan 22, 2016

code LGTM. Still considering docs additions, I assume?

@thaJeztah thaJeztah added this to the 1.10.0 milestone Jan 22, 2016
@thaJeztah
Copy link
Member

We're considering this a bug fix, added to the milestone

@thaJeztah
Copy link
Member

@estesp yes, @cpuguy83 was going to work on docs today

@calavera
Copy link
Contributor

LGTM

@cpuguy83
Copy link
Member Author

Rebased and added docs

@thaJeztah
Copy link
Member

Thanks @cpuguy83 can you also update the note in this section; https://github.com/docker/docker/blob/master/docs/reference/run.md#clean-up---rm ?

@cpuguy83
Copy link
Member Author

@thaJeztah Updated.

@thaJeztah
Copy link
Member

Thanks! Docs LGTM

ping @vdemeester @MHBauer for docs review

@cpuguy83
Copy link
Member Author

Updated -- also fixed windows test (hopefully, we'll see).
@vdemeester PTAL at the doc change


dockerCmd(c, "volume", "create", "--name", "test")

dockerCmd(c, "run", "--rm", "-v", "test:/foo", "-v", prefix+"/bar", "busybox", "true")
Copy link
Member

Choose a reason for hiding this comment

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

You're missing a prefix on the first volume. Also a few lines down.

@vdemeester
Copy link
Member

Docs LGTM 🐹
let's wait for green :)

hello
$ docker rm -v hello

In this example, the volume for `/foo` will remain in tact, but the volume for
Copy link
Contributor

Choose a reason for hiding this comment

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

in tact -> intact

This makes it so when calling `docker run --rm`, or `docker rm -v`, only
volumes specified without a name, e.g. `docker run -v /foo` instead of
`docker run -v awesome:/foo` are removed.

Note that all volumes are named, some are named by the user, some get a
generated name. This is specifically about how the volume was specified
on `run`, assuming that if the user specified it with a name they expect
it to persist after the container is cleaned up.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
@MHBauer
Copy link
Contributor

MHBauer commented Jan 25, 2016

docs nit, but otherwise LTGM. reading the tests helped me understand. The two new ones are simple and good for understanding the behavior. The full cases they represent might make better examples than the given examples that are present, but that is a balance between verbosity and education. It would be best if we could somehow link the code directly into the docs, but I don't think that's feasible.

@cpuguy83
Copy link
Member Author

@MHBauer thanks, fixed the mistake.

@thaJeztah
Copy link
Member

Hit this one on gccgo #19368

@thaJeztah
Copy link
Member

And weird message on win2lin;

22:22:29 INFO: Commmit hash is d17261b
22:22:29 INFO: Attempting curl to ping the DIND daemon
22:22:29 ERROR: Invalid syntax. Default option is not allowed more than '1' time(s).
22:22:29 Type "TIMEOUT /?" for usage.

@tiborvass
Copy link
Contributor

gccgo hit again #19368... merging

tiborvass added a commit that referenced this pull request Jan 26, 2016
On container rm, don't remove named mountpoints
@tiborvass tiborvass merged commit 58c2488 into moby:master Jan 26, 2016
@thaJeztah
Copy link
Member

Added changelog; it's a notable bug fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants