Ver Fonte

Inherit Cmd only if no --entrypoint specified on run

Fixes #5147
Docker-DCO-1.1-Signed-off-by: Alexandr Morozov <lk4d4math@gmail.com> (github: LK4D4)
Alexandr Morozov há 11 anos atrás
pai
commit
aa2d6dbc0c
3 ficheiros alterados com 32 adições e 5 exclusões
  1. 3 2
      builder/builder.go
  2. 26 0
      integration-cli/docker_cli_run_test.go
  3. 3 3
      runconfig/merge.go

+ 3 - 2
builder/builder.go

@@ -71,7 +71,7 @@ type buildFile struct {
 	outOld io.Writer
 	outOld io.Writer
 	sf     *utils.StreamFormatter
 	sf     *utils.StreamFormatter
 
 
-	// cmdSet indicates is CMD was setted in current Dockerfile
+	// cmdSet indicates is CMD was set in current Dockerfile
 	cmdSet bool
 	cmdSet bool
 }
 }
 
 
@@ -202,7 +202,8 @@ func (b *buildFile) CmdRun(args string) error {
 	}
 	}
 
 
 	cmd := b.config.Cmd
 	cmd := b.config.Cmd
-	b.config.Cmd = nil
+	// set Cmd manually, this is special case only for Dockerfiles
+	b.config.Cmd = config.Cmd
 	runconfig.Merge(b.config, config)
 	runconfig.Merge(b.config, config)
 
 
 	defer func(cmd []string) { b.config.Cmd = cmd }(cmd)
 	defer func(cmd []string) { b.config.Cmd = cmd }(cmd)

+ 26 - 0
integration-cli/docker_cli_run_test.go

@@ -1454,3 +1454,29 @@ func TestCopyVolumeContent(t *testing.T) {
 		t.Fatal("Container failed to transfer content to volume")
 		t.Fatal("Container failed to transfer content to volume")
 	}
 	}
 }
 }
+
+func TestRunCleanupCmdOnEntrypoint(t *testing.T) {
+	name := "testrunmdcleanuponentrypoint"
+	defer deleteImages(name)
+	defer deleteAllContainers()
+	if _, err := buildImage(name,
+		`FROM busybox
+		ENTRYPOINT ["echo"]
+        CMD ["testingpoint"]`,
+		true); err != nil {
+		t.Fatal(err)
+	}
+	runCmd := exec.Command(dockerBinary, "run", "--entrypoint", "whoami", name)
+	out, exit, err := runCommandWithOutput(runCmd)
+	if err != nil {
+		t.Fatalf("Error: %v, out: %q", err, out)
+	}
+	if exit != 0 {
+		t.Fatalf("expected exit code 0 received %d, out: %q", exit, out)
+	}
+	out = strings.TrimSpace(out)
+	if out != "root" {
+		t.Fatalf("Expected output root, got %q", out)
+	}
+	logDone("run - cleanup cmd on --entrypoint")
+}

+ 3 - 3
runconfig/merge.go

@@ -84,10 +84,10 @@ func Merge(userConf, imageConf *Config) error {
 		}
 		}
 	}
 	}
 
 
-	if len(userConf.Cmd) == 0 {
-		userConf.Cmd = imageConf.Cmd
-	}
 	if len(userConf.Entrypoint) == 0 {
 	if len(userConf.Entrypoint) == 0 {
+		if len(userConf.Cmd) == 0 {
+			userConf.Cmd = imageConf.Cmd
+		}
 		userConf.Entrypoint = imageConf.Entrypoint
 		userConf.Entrypoint = imageConf.Entrypoint
 	}
 	}
 	if userConf.WorkingDir == "" {
 	if userConf.WorkingDir == "" {