-
Notifications
You must be signed in to change notification settings - Fork 18.6k
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
Move --rm to daemon side #20848
Move --rm to daemon side #20848
Conversation
Also test cases are on working. ping @vdemeester @duglin @tianon @calavera for design review. |
Your description of the proposed behavior seems sane IMO 👍 (So happy to see someone tackling this again 😄) |
346a55c
to
16bfba2
Compare
92300d6
to
3702383
Compare
Happy to see this feature. Do we want to also allow something like |
@phemmer Is there any scenario or benefit for So my current thought is keeping daemon side I'm glad to hear more feedbacks from you 😄 |
@@ -39,8 +39,10 @@ func (daemon *Daemon) containerRestart(container *container.Container, seconds i | |||
return err | |||
} | |||
|
|||
if err := daemon.containerStart(container); err != nil { | |||
return err | |||
if !container.HostConfig.AutoRemove { |
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.
I'm not sure about this one. I think we should allow the client to restart a container w/o it being removed. Granted this means that "docker stop" and "docker start" will not be the exact same as "docker restart" in this case but I think this is what the user would expect - otherwise they wouldn't be trying to do "docker restart" at all.
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.
This is limited by current design of restart policy, if we run docker stop
on one container, it will stop immediately no matter what its restart policy is. According to our previous discussion, --rm
should mean "delete the container when the container stops and won't restart any more", so if it stops, the container is removed, there's no need to start it again, and the start is bound to fail.
That's why I'm saying:
"4. docker restart
a --rm
container will behave like a docker stop
, container will be stopped and removed."
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.
It's also restricted by technique, I can't find a method to distinguish stop command from docker restart
or pure docker stop
, I can only detect the container is stopped and should be removed.
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.
But if you don't add this if-statement then I think it'll act the way the end user expects. There's a difference between "docker stop" and "docker restart". Stop is asking for the container to fully stop running. Restart is just asking for it to be rebooted NOT stopped - not unlike a daemon reboot would. If we don't do this then there's no difference between "docker stop" and "docker restart" - and I don't think that's correct. A restart is the user's way of explicitly telling us that they don't want the container to be fully stopped, otherwise they would just use "stop".
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.
I totally agree with you about the behavior, but I think remove this if clause won't make it work. Maybe I need to do some trick, for example, set --rm=false
before restart, and restore it after restart. I'll make some try.
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.
I'll try to play with it too- one thing to try is to set the restart policy to "always" temporarily so that we don't need to explicitly call start ourselves :-)
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.
I'm afraid setting restart policy to always
won't work, if you docker stop
a container with restart policy "always", it will stop and don't restart. This is strange, I would expect it will restart no matter how it is stopped.
I guess this is also limited by technique.
Overall design looks good!! Just one question about "docker restart". |
Design seems good and looks like behavior is conforming to test expectations, except for one test: @duglin's question is interesting, but was an impossible case in current |
@estesp I'll try to fix the test case. |
3702383
to
c2fcacb
Compare
@WeiZhang555 yes something like that looks good. I need to think more about the use of the defer in that case but in general yes! |
// set AutoRemove flag to false before stop so the container won't be | ||
// removed during restart process | ||
autoRemove := container.HostConfig.AutoRemove | ||
defer func() { |
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.
Let me know if you think I'm being paranoid, but I'd prefer this:
// set AutoRemove flag to false before stop so the container won't be
// removed during restart process
autoRemove := container.HostConfig.AutoRemove
container.HostConfig.AutoRemove = false
err := daemon.containerStop(container, seconds)
container.HostConfig.AutoRemove = autoRemove
if err != nil {
return err
}
if err := daemon.containerStart(container); err != nil {
return err
}
because I'm worried about the defer resetting the container.HostConfig.AutoRemove when perhaps it shouldn't. For example, normally I wouldn't expect containerStart() to change that value but you never know what might happen in the future. So to prevent unexpected side-effects of the defer, I think it would be safer to just clear and then reset AutoRemove right around the containerStop() since that's really the only code we need to be worried about.
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.
This is good, I will modify as per your suggestion 😄
keep forgetting that this is still in design review, so making it official: SGTM |
Design sgtm as well, some questions / thoughts:
|
Good point, what should we do in case of |
Don't we have a policy of not supporting newer clients with older daemons? If nothing else I think the daemon will complain, no? |
We don't really support new client + older daemon, so should probably be fine. Guess the daemon will silently ignore the option, just the user may be surprised that the container is not removed in that case |
Yes, a string type will be better for future extension, but I can't identify its scenarios clearly. For example:
So maybe let "--rm bool" only do simple auto clean work is already good enough?
Yes, it will work.
Ah, this is awful, I prefer not support this. Just did a quick test, new client+older daemon, it reports:
Older daemon did a good job, I think this is already good enough. What is everyone thinking of these? |
c2fcacb
to
9568a41
Compare
Docs for moby#20848: move "--rm" to daemon side. Add description for introduced API changes. Signed-off-by: Zhang Wei <zhangwei555@huawei.com>
Hi, May I know when docker 1.13.0 is coming out? |
@codingground release candidates are available for testing now https://github.com/docker/docker/releases |
Thanks ThaJeztah. Its running great and --rm option with server is lovely. Now I'm able to create upto 1000 instances with ease and my Coding Ground is up and running without any further issue. |
@codingground thanks for confirming! |
This seems not to work with docker-compose. |
@907th Not sure what that means, but if you have a specific issue with docker compose, please open an issue on github.com/docker/compose. Thanks. |
@907th please don't comment on old PR's and issues, I answered on your other comment; #28747 (comment) |
I'm locking the conversation on this PR. If you arrive here to report a bug, please open a new issue with details. Commenting on closed PR's is not the right place to report bugs, as they easily go unnoticed, and may miss the required information. |
Fixes #20334
Fixes #16575
Fixes #6003
Fixes #20744
Fixes #12157
So many related issues, I won't list them one by one.
--rm
is a client side flag which caused lots of problems:--rm
container, this container won't be autoremoved.docker run --rm busybox fakecmd
will exit without cleanup.In a word, client side
--rm
flag isn't sufficient for garbage collection. Move the--rm
flag to daemon will be more reasonable.What this commit do is:
--rm
on daemon side, adding one flagAutoRemove
into HostConfig.run --rm -d
, no conflicting--rm
and-d
any more, auto-remove can work on detach mode.docker restart
a--rm
container will succeed, the container won't be autoremoved.This commit will help a lot for daemon to do garbage collection for temporary containers for short term job.
Signed-off-by: Zhang Wei zhangwei555@huawei.com