Skip to content

Commit c92377e

Browse files
rmccooey27rhatdan
authored andcommitted
docker kill should return error if container is not running.
Assuming that docker kill is trying to actually kill the container is a mistake. If the container is not running we should report it back to the caller as a error. Docker-DCO-1.1-Signed-off-by: Dan Walsh <[email protected]> (github: rhatdan) Docker-DCO-1.1-Signed-off-by: Regan McCooey <[email protected]> (github: rmccooey27) Docker-DCO-1.1-Signed-off-by: Regan McCooey <[email protected]> (github: rhatdan)
1 parent 300a12f commit c92377e

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

api/server/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ func (s *Server) postContainersKill(eng *engine.Engine, version version.Version,
286286
name := vars["name"]
287287

288288
// If we have a signal, look at it. Otherwise, do nothing
289-
if sigStr := vars["signal"]; sigStr != "" {
289+
if sigStr := r.Form.Get("signal"); sigStr != "" {
290290
// Check if we passed the signal as a number:
291291
// The largest legal signal is 31, so let's parse on 5 bits
292292
sig, err = strconv.ParseUint(sigStr, 10, 5)

daemon/container.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ func (container *Container) KillSig(sig int) error {
710710
}
711711

712712
if !container.Running {
713-
return nil
713+
return fmt.Errorf("Container %s is not running", container.ID)
714714
}
715715

716716
// signal to the monitor that it should not restart the container

integration-cli/docker_cli_kill_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,28 @@ func (s *DockerSuite) TestKillContainer(c *check.C) {
4040

4141
}
4242

43+
func (s *DockerSuite) TestKillofStoppedContainer(c *check.C) {
44+
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
45+
out, _, err := runCommandWithOutput(runCmd)
46+
if err != nil {
47+
c.Fatal(out, err)
48+
}
49+
50+
cleanedContainerID := strings.TrimSpace(out)
51+
52+
stopCmd := exec.Command(dockerBinary, "stop", cleanedContainerID)
53+
if out, _, err = runCommandWithOutput(stopCmd); err != nil {
54+
c.Fatalf("failed to stop container: %s, %v", out, err)
55+
}
56+
57+
killCmd := exec.Command(dockerBinary, "kill", "-s", "30", cleanedContainerID)
58+
if _, _, err = runCommandWithOutput(killCmd); err == nil {
59+
c.Fatalf("kill succeeded on a stopped container")
60+
}
61+
62+
deleteContainer(cleanedContainerID)
63+
}
64+
4365
func (s *DockerSuite) TestKillDifferentUserContainer(c *check.C) {
4466
runCmd := exec.Command(dockerBinary, "run", "-u", "daemon", "-d", "busybox", "top")
4567
out, _, err := runCommandWithOutput(runCmd)

0 commit comments

Comments
 (0)