diff --git a/daemon/container.go b/daemon/container.go index 4991846f41..9bf0b9c60a 100644 --- a/daemon/container.go +++ b/daemon/container.go @@ -364,7 +364,7 @@ func (container *Container) KillSig(sig int) error { } 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 @@ -441,7 +441,7 @@ func (container *Container) Unpause() error { func (container *Container) Kill() error { if !container.IsRunning() { - return nil + return fmt.Errorf("Container %s is not running", container.ID) } // 1. Send SIGKILL diff --git a/integration-cli/docker_cli_kill_test.go b/integration-cli/docker_cli_kill_test.go index 8c0031a4a1..fc144fa17c 100644 --- a/integration-cli/docker_cli_kill_test.go +++ b/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) { runCmd := exec.Command(dockerBinary, "run", "-u", "daemon", "-d", "busybox", "top") out, _, err := runCommandWithOutput(runCmd)