Browse code

builder: Restore /bin/sh handling in CMD when entrypoint is specified with JSON

Docker-DCO-1.1-Signed-off-by: Erik Hollensbe <github@hollensbe.org> (github: erikh)

Erik Hollensbe authored on 2014/10/28 06:15:28
Showing 2 changed files
... ...
@@ -234,7 +234,7 @@ func run(b *Builder, args []string, attributes map[string]bool, original string)
234 234
 func cmd(b *Builder, args []string, attributes map[string]bool, original string) error {
235 235
 	b.Config.Cmd = handleJsonArgs(args, attributes)
236 236
 
237
-	if !attributes["json"] && len(b.Config.Entrypoint) == 0 {
237
+	if !attributes["json"] {
238 238
 		b.Config.Cmd = append([]string{"/bin/sh", "-c"}, b.Config.Cmd...)
239 239
 	}
240 240
 
... ...
@@ -16,6 +16,40 @@ import (
16 16
 	"github.com/docker/docker/pkg/archive"
17 17
 )
18 18
 
19
+func TestBuildShCmdJSONEntrypoint(t *testing.T) {
20
+	name := "testbuildshcmdjsonentrypoint"
21
+	defer deleteImages(name)
22
+
23
+	_, err := buildImage(
24
+		name,
25
+		`
26
+    FROM busybox
27
+    ENTRYPOINT ["/bin/echo"]
28
+    CMD echo test
29
+    `,
30
+		true)
31
+
32
+	if err != nil {
33
+		t.Fatal(err)
34
+	}
35
+
36
+	out, _, err := runCommandWithOutput(
37
+		exec.Command(
38
+			dockerBinary,
39
+			"run",
40
+			name))
41
+
42
+	if err != nil {
43
+		t.Fatal(err)
44
+	}
45
+
46
+	if strings.TrimSpace(out) != "/bin/sh -c echo test" {
47
+		t.Fatal("CMD did not contain /bin/sh -c")
48
+	}
49
+
50
+	logDone("build - CMD should always contain /bin/sh -c when specified without JSON")
51
+}
52
+
19 53
 func TestBuildEnvironmentReplacementUser(t *testing.T) {
20 54
 	name := "testbuildenvironmentreplacement"
21 55
 	defer deleteImages(name)