Browse code

builder: Fix setting command with custom shell

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>

Tonis Tiigi authored on 2017/03/31 05:29:21
Showing 2 changed files
... ...
@@ -827,7 +827,7 @@ func errTooManyArguments(command string) error {
827 827
 // shell-form of RUN, ENTRYPOINT and CMD instructions
828 828
 func getShell(c *container.Config) []string {
829 829
 	if 0 == len(c.Shell) {
830
-		return defaultShell[:]
830
+		return append([]string{}, defaultShell[:]...)
831 831
 	}
832
-	return c.Shell[:]
832
+	return append([]string{}, c.Shell[:]...)
833 833
 }
... ...
@@ -6039,3 +6039,18 @@ func (s *DockerSuite) TestBuildLineErrorWithComments(c *check.C) {
6039 6039
 		Err:      "Dockerfile parse error line 5: Unknown instruction: NOINSTRUCTION",
6040 6040
 	})
6041 6041
 }
6042
+
6043
+// #31957
6044
+func (s *DockerSuite) TestBuildSetCommandWithDefinedShell(c *check.C) {
6045
+	buildImageSuccessfully(c, "build1", build.WithDockerfile(`
6046
+FROM busybox
6047
+SHELL ["/bin/sh", "-c"]
6048
+`))
6049
+	buildImageSuccessfully(c, "build2", build.WithDockerfile(`
6050
+FROM build1
6051
+CMD echo foo
6052
+`))
6053
+
6054
+	out, _ := dockerCmd(c, "inspect", "--format", "{{ json .Config.Cmd }}", "build2")
6055
+	c.Assert(strings.TrimSpace(out), checker.Equals, `["/bin/sh","-c","echo foo"]`)
6056
+}