Browse code

LCOW: fix using wrong shell for healthchecks

As reported in docker/compose#6445, when deploying a Linux
container on Windows (LCOW), the daemon made the wrong assumption
when deciding which shell to use to execute the healthcheck, looking
at the host's platform instead of the container's platform.

This patch adds a check for the container's platform when deploying
on Windows, and sets the correct shell.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2019/06/21 20:51:59
Showing 1 changed files
... ...
@@ -10,7 +10,6 @@ import (
10 10
 	"time"
11 11
 
12 12
 	"github.com/docker/docker/api/types"
13
-	containertypes "github.com/docker/docker/api/types/container"
14 13
 	"github.com/docker/docker/api/types/strslice"
15 14
 	"github.com/docker/docker/container"
16 15
 	"github.com/docker/docker/daemon/exec"
... ...
@@ -65,7 +64,7 @@ type cmdProbe struct {
65 65
 func (p *cmdProbe) run(ctx context.Context, d *Daemon, cntr *container.Container) (*types.HealthcheckResult, error) {
66 66
 	cmdSlice := strslice.StrSlice(cntr.Config.Healthcheck.Test)[1:]
67 67
 	if p.shell {
68
-		cmdSlice = append(getShell(cntr.Config), cmdSlice...)
68
+		cmdSlice = append(getShell(cntr), cmdSlice...)
69 69
 	}
70 70
 	entrypoint, args := d.getEntrypointAndArgs(strslice.StrSlice{}, cmdSlice)
71 71
 	execConfig := exec.NewConfig()
... ...
@@ -376,12 +375,15 @@ func min(x, y int) int {
376 376
 	return y
377 377
 }
378 378
 
379
-func getShell(config *containertypes.Config) []string {
380
-	if len(config.Shell) != 0 {
381
-		return config.Shell
379
+func getShell(cntr *container.Container) []string {
380
+	if len(cntr.Config.Shell) != 0 {
381
+		return cntr.Config.Shell
382 382
 	}
383 383
 	if runtime.GOOS != "windows" {
384 384
 		return []string{"/bin/sh", "-c"}
385 385
 	}
386
+	if cntr.OS != runtime.GOOS {
387
+		return []string{"/bin/sh", "-c"}
388
+	}
386 389
 	return []string{"cmd", "/S", "/C"}
387 390
 }