1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #12371 from rhatdan/kill

docker kill should return error if container is not running.
This commit is contained in:
Doug Davis 2015-06-10 08:32:57 -07:00
commit 46af724e81
2 changed files with 18 additions and 2 deletions

View file

@ -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

View file

@ -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)