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