1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

[17.03.x] fix autoremove on pre 1.25 API

Commit 87a53468b2 cherry-picked
changes into the 17.03 branch to make the client
skip auto-removing containers on API 1.25 and up.

Some changes got lost during that cherry-pick,
resulting in 17.03 clients to not fall back to
the old behavior when connecting to API version
1.24 or below.

This patch addresses this issue for the 17.03
branch by copying the `HostConfig.AutoRemove` property
to a local variable before it is overridden
in `ContainerCreate()`.

This change is not needed on "master" (17.04-dev),
which does not have this problem.

Thanks to Josh Hawn for finding this bug.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2017-03-09 11:59:11 +01:00
parent b2cba289fc
commit 19bbb4e9f0
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -136,6 +136,9 @@ func runRun(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *runOptions
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)
if err != nil {
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
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)
if hostConfig.AutoRemove {
if autoRemove {
// wait container to be removed
<-statusChan
}