Parcourir la source

Merge pull request #12371 from rhatdan/kill

docker kill should return error if container is not running.
Doug Davis il y a 10 ans
Parent
commit
46af724e81
2 fichiers modifiés avec 18 ajouts et 2 suppressions
  1. 2 2
      daemon/container.go
  2. 16 0
      integration-cli/docker_cli_kill_test.go

+ 2 - 2
daemon/container.go

@@ -364,7 +364,7 @@ func (container *Container) KillSig(sig int) error {
 	}
 	}
 
 
 	if !container.Running {
 	if !container.Running {
-		return nil
+		return fmt.Errorf("Container %s is not running", container.ID)
 	}
 	}
 
 
 	// signal to the monitor that it should not restart the container
 	// signal to the monitor that it should not restart the container
@@ -441,7 +441,7 @@ func (container *Container) Unpause() error {
 
 
 func (container *Container) Kill() error {
 func (container *Container) Kill() error {
 	if !container.IsRunning() {
 	if !container.IsRunning() {
-		return nil
+		return fmt.Errorf("Container %s is not running", container.ID)
 	}
 	}
 
 
 	// 1. Send SIGKILL
 	// 1. Send SIGKILL

+ 16 - 0
integration-cli/docker_cli_kill_test.go

@@ -33,6 +33,22 @@ func (s *DockerSuite) TestKillContainer(c *check.C) {
 	}
 	}
 }
 }
 
 
+func (s *DockerSuite) TestKillofStoppedContainer(c *check.C) {
+	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
+	out, _, err := runCommandWithOutput(runCmd)
+	c.Assert(err, check.IsNil)
+
+	cleanedContainerID := strings.TrimSpace(out)
+
+	stopCmd := exec.Command(dockerBinary, "stop", cleanedContainerID)
+	out, _, err = runCommandWithOutput(stopCmd)
+	c.Assert(err, check.IsNil)
+
+	killCmd := exec.Command(dockerBinary, "kill", "-s", "30", cleanedContainerID)
+	_, _, err = runCommandWithOutput(killCmd)
+	c.Assert(err, check.Not(check.IsNil), check.Commentf("Container %s is not running", cleanedContainerID))
+}
+
 func (s *DockerSuite) TestKillDifferentUserContainer(c *check.C) {
 func (s *DockerSuite) TestKillDifferentUserContainer(c *check.C) {
 	runCmd := exec.Command(dockerBinary, "run", "-u", "daemon", "-d", "busybox", "top")
 	runCmd := exec.Command(dockerBinary, "run", "-u", "daemon", "-d", "busybox", "top")
 	out, _, err := runCommandWithOutput(runCmd)
 	out, _, err := runCommandWithOutput(runCmd)