Merge pull request #12371 from rhatdan/kill
docker kill should return error if container is not running.
This commit is contained in:
commit
46af724e81
2 changed files with 18 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue