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
Conversation
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") |
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.
can we assert that bar
is not in the output too somehow?
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.
We are, we are doing checker.Equals
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.
oh right, nevermind, thanks.
sounds like a great plan 👍 |
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 |
We may need to update some documentation explaining this |
1305a7f
to
96d8415
Compare
@thaJeztah I'll take a look at the docs tomorrow. |
@cpuguy83 👍 just mentioning it to prevent trigger-happy merges 😄 |
@cpuguy83 I tested your branch. This scenario does not work, the volume still be remove if the named volume is from
Remove container
seems we should also handle https://github.com/docker/docker/blob/master/daemon/volumes.go#L73 |
96d8415
to
2451c38
Compare
@coolljt0725 Nice catch! Updated with a fix and another test. |
code LGTM. Still considering docs additions, I assume? |
We're considering this a bug fix, added to the milestone |
LGTM |
867b854
to
f94c1f4
Compare
Rebased and added docs |
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 ? |
f94c1f4
to
1f9fec4
Compare
@thaJeztah Updated. |
Thanks! Docs LGTM ping @vdemeester @MHBauer for docs review |
Updated -- also fixed windows test (hopefully, we'll see). |
|
||
dockerCmd(c, "volume", "create", "--name", "test") | ||
|
||
dockerCmd(c, "run", "--rm", "-v", "test:/foo", "-v", prefix+"/bar", "busybox", "true") |
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.
You're missing a prefix
on the first volume. Also a few lines down.
4c64404
to
7a6a1a2
Compare
Docs LGTM 🐹 |
hello | ||
$ docker rm -v hello | ||
|
||
In this example, the volume for `/foo` will remain in tact, but the volume for |
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.
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>
7a6a1a2
to
dd7d1c8
Compare
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. |
@MHBauer thanks, fixed the mistake. |
Hit this one on gccgo #19368 |
And weird message on win2lin;
|
gccgo hit again #19368... merging |
On container rm, don't remove named mountpoints
Added changelog; it's a notable bug fix |
This makes it so when calling
docker run --rm
, ordocker rm -v
, onlyvolumes specified without a name, e.g.
docker run -v /foo
instead ofdocker 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 expectit to persist after the container is cleaned up.
Fixes #17907