github.com/tsuna/docker@v1.7.0-rc3/api/client/stop.go (about) 1 package client 2 3 import ( 4 "fmt" 5 "net/url" 6 "strconv" 7 8 flag "github.com/docker/docker/pkg/mflag" 9 ) 10 11 // CmdStop stops one or more running containers. 12 // 13 // A running container is stopped by first sending SIGTERM and then SIGKILL if the container fails to stop within a grace period (the default is 10 seconds). 14 // 15 // Usage: docker stop [OPTIONS] CONTAINER [CONTAINER...] 16 func (cli *DockerCli) CmdStop(args ...string) error { 17 cmd := cli.Subcmd("stop", "CONTAINER [CONTAINER...]", "Stop a running container by sending SIGTERM and then SIGKILL after a\ngrace period", true) 18 nSeconds := cmd.Int([]string{"t", "-time"}, 10, "Seconds to wait for stop before killing it") 19 cmd.Require(flag.Min, 1) 20 21 cmd.ParseFlags(args, true) 22 23 v := url.Values{} 24 v.Set("t", strconv.Itoa(*nSeconds)) 25 26 var errNames []string 27 for _, name := range cmd.Args() { 28 _, _, err := readBody(cli.call("POST", "/containers/"+name+"/stop?"+v.Encode(), nil, nil)) 29 if err != nil { 30 fmt.Fprintf(cli.err, "%s\n", err) 31 errNames = append(errNames, name) 32 } else { 33 fmt.Fprintf(cli.out, "%s\n", name) 34 } 35 } 36 if len(errNames) > 0 { 37 return fmt.Errorf("Error: failed to stop containers: %v", errNames) 38 } 39 return nil 40 }