github.com/ncdc/docker@v0.10.1-0.20160129113957-6c6729ef5b74/api/client/stop.go (about) 1 package client 2 3 import ( 4 "fmt" 5 "strings" 6 7 Cli "github.com/docker/docker/cli" 8 flag "github.com/docker/docker/pkg/mflag" 9 ) 10 11 // CmdStop stops one or more 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", []string{"CONTAINER [CONTAINER...]"}, Cli.DockerCommands["stop"].Description+".\nSending SIGTERM and then SIGKILL after a grace 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 var errs []string 24 for _, name := range cmd.Args() { 25 if err := cli.client.ContainerStop(name, *nSeconds); err != nil { 26 errs = append(errs, fmt.Sprintf("Failed to stop container (%s): %s", name, err)) 27 } else { 28 fmt.Fprintf(cli.out, "%s\n", name) 29 } 30 } 31 if len(errs) > 0 { 32 return fmt.Errorf("%s", strings.Join(errs, "\n")) 33 } 34 return nil 35 }