Merge pull request #31692 from thaJeztah/17.03.x-fix-autoremove-on-older-api
[17.03.x] fix autoremove on older api
This commit is contained in:
commit
502b068b3c
2 changed files with 29 additions and 2 deletions
|
@ -136,6 +136,9 @@ func runRun(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *runOptions
|
||||||
|
|
||||||
ctx, cancelFun := context.WithCancel(context.Background())
|
ctx, cancelFun := context.WithCancel(context.Background())
|
||||||
|
|
||||||
|
// preserve AutoRemove state. createContainer() / ContainerCreate() disables daemon-side auto-remove on API < 1.25
|
||||||
|
autoRemove := hostConfig.AutoRemove
|
||||||
|
|
||||||
createResponse, err := createContainer(ctx, dockerCli, config, hostConfig, networkingConfig, hostConfig.ContainerIDFile, opts.name)
|
createResponse, err := createContainer(ctx, dockerCli, config, hostConfig, networkingConfig, hostConfig.ContainerIDFile, opts.name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
reportError(stderr, cmdPath, err.Error(), true)
|
reportError(stderr, cmdPath, err.Error(), true)
|
||||||
|
@ -207,7 +210,7 @@ func runRun(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *runOptions
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
statusChan := waitExitOrRemoved(ctx, dockerCli, createResponse.ID, hostConfig.AutoRemove)
|
statusChan := waitExitOrRemoved(ctx, dockerCli, createResponse.ID, autoRemove)
|
||||||
|
|
||||||
//start the container
|
//start the container
|
||||||
if err := client.ContainerStart(ctx, createResponse.ID, types.ContainerStartOptions{}); err != nil {
|
if err := client.ContainerStart(ctx, createResponse.ID, types.ContainerStartOptions{}); err != nil {
|
||||||
|
@ -220,7 +223,7 @@ func runRun(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *runOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
reportError(stderr, cmdPath, err.Error(), false)
|
reportError(stderr, cmdPath, err.Error(), false)
|
||||||
if hostConfig.AutoRemove {
|
if autoRemove {
|
||||||
// wait container to be removed
|
// wait container to be removed
|
||||||
<-statusChan
|
<-statusChan
|
||||||
}
|
}
|
||||||
|
|
|
@ -4421,6 +4421,30 @@ func (s *DockerSuite) TestRunRmAndWait(c *check.C) {
|
||||||
c.Assert(code, checker.Equals, 0)
|
c.Assert(code, checker.Equals, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test that auto-remove is performed by the daemon (API 1.25 and above)
|
||||||
|
func (s *DockerSuite) TestRunRm(c *check.C) {
|
||||||
|
name := "miss-me-when-im-gone"
|
||||||
|
dockerCmd(c, "run", "--name="+name, "--rm", "busybox")
|
||||||
|
|
||||||
|
_, err := inspectFieldWithError(name, "name")
|
||||||
|
c.Assert(err, checker.Not(check.IsNil))
|
||||||
|
c.Assert(err.Error(), checker.Contains, "No such object: "+name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test that auto-remove is performed by the client on API versions that do not support daemon-side api-remove (API < 1.25)
|
||||||
|
func (s *DockerSuite) TestRunRmPre125Api(c *check.C) {
|
||||||
|
name := "miss-me-when-im-gone"
|
||||||
|
result := icmd.RunCmd(icmd.Cmd{
|
||||||
|
Command: binaryWithArgs("run", "--name="+name, "--rm", "busybox"),
|
||||||
|
Env: appendBaseEnv(false, "DOCKER_API_VERSION=1.24"),
|
||||||
|
})
|
||||||
|
c.Assert(result, icmd.Matches, icmd.Success)
|
||||||
|
|
||||||
|
_, err := inspectFieldWithError(name, "name")
|
||||||
|
c.Assert(err, checker.Not(check.IsNil))
|
||||||
|
c.Assert(err.Error(), checker.Contains, "No such object: "+name)
|
||||||
|
}
|
||||||
|
|
||||||
// Test case for #23498
|
// Test case for #23498
|
||||||
func (s *DockerSuite) TestRunUnsetEntrypoint(c *check.C) {
|
func (s *DockerSuite) TestRunUnsetEntrypoint(c *check.C) {
|
||||||
testRequires(c, DaemonIsLinux)
|
testRequires(c, DaemonIsLinux)
|
||||||
|
|
Loading…
Reference in a new issue