github.com/ncdc/docker@v0.10.1-0.20160129113957-6c6729ef5b74/api/client/restart.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 // CmdRestart restarts one or more containers. 12 // 13 // Usage: docker restart [OPTIONS] CONTAINER [CONTAINER...] 14 func (cli *DockerCli) CmdRestart(args ...string) error { 15 cmd := Cli.Subcmd("restart", []string{"CONTAINER [CONTAINER...]"}, Cli.DockerCommands["restart"].Description, true) 16 nSeconds := cmd.Int([]string{"t", "-time"}, 10, "Seconds to wait for stop before killing the container") 17 cmd.Require(flag.Min, 1) 18 19 cmd.ParseFlags(args, true) 20 21 var errs []string 22 for _, name := range cmd.Args() { 23 if err := cli.client.ContainerRestart(name, *nSeconds); err != nil { 24 errs = append(errs, fmt.Sprintf("Failed to kill container (%s): %s", name, err)) 25 } else { 26 fmt.Fprintf(cli.out, "%s\n", name) 27 } 28 } 29 if len(errs) > 0 { 30 return fmt.Errorf("%s", strings.Join(errs, "\n")) 31 } 32 return nil 33 }