github.com/hamo/docker@v1.11.1/api/client/restart.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  // CmdRestart restarts one or more containers.
    14  //
    15  // Usage: docker restart [OPTIONS] CONTAINER [CONTAINER...]
    16  func (cli *DockerCli) CmdRestart(args ...string) error {
    17  	cmd := Cli.Subcmd("restart", []string{"CONTAINER [CONTAINER...]"}, Cli.DockerCommands["restart"].Description, true)
    18  	nSeconds := cmd.Int([]string{"t", "-time"}, 10, "Seconds to wait for stop before killing the container")
    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.ContainerRestart(context.Background(), name, *nSeconds); err != nil {
    26  			errs = append(errs, err.Error())
    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  }