Browse code

[17.03.x] fix autoremove on pre 1.25 API

Commit 87a53468b230e6592c547f29f6279a640e368445 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>

Sebastiaan van Stijn authored on 2017/03/09 19:59:11
Showing 1 changed files
... ...
@@ -136,6 +136,9 @@ func runRun(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *runOptions
136 136
 
137 137
 	ctx, cancelFun := context.WithCancel(context.Background())
138 138
 
139
+	// preserve AutoRemove state. createContainer() / ContainerCreate() disables daemon-side auto-remove on API < 1.25
140
+	autoRemove := hostConfig.AutoRemove
141
+
139 142
 	createResponse, err := createContainer(ctx, dockerCli, config, hostConfig, networkingConfig, hostConfig.ContainerIDFile, opts.name)
140 143
 	if err != nil {
141 144
 		reportError(stderr, cmdPath, err.Error(), true)
... ...
@@ -207,7 +210,7 @@ func runRun(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *runOptions
207 207
 		})
208 208
 	}
209 209
 
210
-	statusChan := waitExitOrRemoved(ctx, dockerCli, createResponse.ID, hostConfig.AutoRemove)
210
+	statusChan := waitExitOrRemoved(ctx, dockerCli, createResponse.ID, autoRemove)
211 211
 
212 212
 	//start the container
213 213
 	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
220 220
 		}
221 221
 
222 222
 		reportError(stderr, cmdPath, err.Error(), false)
223
-		if hostConfig.AutoRemove {
223
+		if autoRemove {
224 224
 			// wait container to be removed
225 225
 			<-statusChan
226 226
 		}