github.com/a4a881d4/docker@v1.9.0-rc2/api/client/kill.go (about) 1 package client 2 3 import ( 4 "fmt" 5 6 Cli "github.com/docker/docker/cli" 7 flag "github.com/docker/docker/pkg/mflag" 8 ) 9 10 // CmdKill kills one or more running container using SIGKILL or a specified signal. 11 // 12 // Usage: docker kill [OPTIONS] CONTAINER [CONTAINER...] 13 func (cli *DockerCli) CmdKill(args ...string) error { 14 cmd := Cli.Subcmd("kill", []string{"CONTAINER [CONTAINER...]"}, Cli.DockerCommands["kill"].Description, true) 15 signal := cmd.String([]string{"s", "-signal"}, "KILL", "Signal to send to the container") 16 cmd.Require(flag.Min, 1) 17 18 cmd.ParseFlags(args, true) 19 20 var errNames []string 21 for _, name := range cmd.Args() { 22 if _, _, err := readBody(cli.call("POST", fmt.Sprintf("/containers/%s/kill?signal=%s", name, *signal), nil, nil)); err != nil { 23 fmt.Fprintf(cli.err, "%s\n", err) 24 errNames = append(errNames, name) 25 } else { 26 fmt.Fprintf(cli.out, "%s\n", name) 27 } 28 } 29 if len(errNames) > 0 { 30 return fmt.Errorf("Error: failed to kill containers: %v", errNames) 31 } 32 return nil 33 }