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