restart.go 926 B

123456789101112131415161718192021222324252627282930313233
  1. package client
  2. import (
  3. "fmt"
  4. "strings"
  5. Cli "github.com/docker/docker/cli"
  6. flag "github.com/docker/docker/pkg/mflag"
  7. )
  8. // CmdRestart restarts one or more containers.
  9. //
  10. // Usage: docker restart [OPTIONS] CONTAINER [CONTAINER...]
  11. func (cli *DockerCli) CmdRestart(args ...string) error {
  12. cmd := Cli.Subcmd("restart", []string{"CONTAINER [CONTAINER...]"}, Cli.DockerCommands["restart"].Description, true)
  13. nSeconds := cmd.Int([]string{"t", "-time"}, 10, "Seconds to wait for stop before killing the container")
  14. cmd.Require(flag.Min, 1)
  15. cmd.ParseFlags(args, true)
  16. var errs []string
  17. for _, name := range cmd.Args() {
  18. if err := cli.client.ContainerRestart(name, *nSeconds); err != nil {
  19. errs = append(errs, fmt.Sprintf("Failed to kill container (%s): %s", name, err))
  20. } else {
  21. fmt.Fprintf(cli.out, "%s\n", name)
  22. }
  23. }
  24. if len(errs) > 0 {
  25. return fmt.Errorf("%s", strings.Join(errs, "\n"))
  26. }
  27. return nil
  28. }