From a1fa59ea123555a910c1de1f7b88b75000f2bec4 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Thu, 30 Mar 2017 13:29:21 -0700 Subject: [PATCH] builder: Fix setting command with custom shell Signed-off-by: Tonis Tiigi --- builder/dockerfile/dispatchers.go | 4 ++-- integration-cli/docker_cli_build_test.go | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/builder/dockerfile/dispatchers.go b/builder/dockerfile/dispatchers.go index 8982387e779d3..1b875b9dc932b 100644 --- a/builder/dockerfile/dispatchers.go +++ b/builder/dockerfile/dispatchers.go @@ -827,7 +827,7 @@ func errTooManyArguments(command string) error { // shell-form of RUN, ENTRYPOINT and CMD instructions func getShell(c *container.Config) []string { if 0 == len(c.Shell) { - return defaultShell[:] + return append([]string{}, defaultShell[:]...) } - return c.Shell[:] + return append([]string{}, c.Shell[:]...) } diff --git a/integration-cli/docker_cli_build_test.go b/integration-cli/docker_cli_build_test.go index 7a42d1f92d0b4..bd712615ab5ee 100644 --- a/integration-cli/docker_cli_build_test.go +++ b/integration-cli/docker_cli_build_test.go @@ -6039,3 +6039,18 @@ func (s *DockerSuite) TestBuildLineErrorWithComments(c *check.C) { Err: "Dockerfile parse error line 5: Unknown instruction: NOINSTRUCTION", }) } + +// #31957 +func (s *DockerSuite) TestBuildSetCommandWithDefinedShell(c *check.C) { + buildImageSuccessfully(c, "build1", build.WithDockerfile(` +FROM busybox +SHELL ["/bin/sh", "-c"] +`)) + buildImageSuccessfully(c, "build2", build.WithDockerfile(` +FROM build1 +CMD echo foo +`)) + + out, _ := dockerCmd(c, "inspect", "--format", "{{ json .Config.Cmd }}", "build2") + c.Assert(strings.TrimSpace(out), checker.Equals, `["/bin/sh","-c","echo foo"]`) +}