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