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