Skip to content

Commit 3e6a13c

Browse files
committed
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 <[email protected]>
1 parent 52c1667 commit 3e6a13c

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

daemon/health.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"time"
1111

1212
"github.com/docker/docker/api/types"
13-
containertypes "github.com/docker/docker/api/types/container"
1413
"github.com/docker/docker/api/types/strslice"
1514
"github.com/docker/docker/container"
1615
"github.com/docker/docker/daemon/exec"
@@ -65,7 +64,7 @@ type cmdProbe struct {
6564
func (p *cmdProbe) run(ctx context.Context, d *Daemon, cntr *container.Container) (*types.HealthcheckResult, error) {
6665
cmdSlice := strslice.StrSlice(cntr.Config.Healthcheck.Test)[1:]
6766
if p.shell {
68-
cmdSlice = append(getShell(cntr.Config), cmdSlice...)
67+
cmdSlice = append(getShell(cntr), cmdSlice...)
6968
}
7069
entrypoint, args := d.getEntrypointAndArgs(strslice.StrSlice{}, cmdSlice)
7170
execConfig := exec.NewConfig()
@@ -376,12 +375,15 @@ func min(x, y int) int {
376375
return y
377376
}
378377

379-
func getShell(config *containertypes.Config) []string {
380-
if len(config.Shell) != 0 {
381-
return config.Shell
378+
func getShell(cntr *container.Container) []string {
379+
if len(cntr.Config.Shell) != 0 {
380+
return cntr.Config.Shell
382381
}
383382
if runtime.GOOS != "windows" {
384383
return []string{"/bin/sh", "-c"}
385384
}
385+
if cntr.OS != runtime.GOOS {
386+
return []string{"/bin/sh", "-c"}
387+
}
386388
return []string{"cmd", "/S", "/C"}
387389
}

0 commit comments

Comments
 (0)