github.com/rish1988/moby@v25.0.2+incompatible/client/container_restart.go (about) 1 package client // import "github.com/docker/docker/client" 2 3 import ( 4 "context" 5 "net/url" 6 "strconv" 7 8 "github.com/docker/docker/api/types/container" 9 "github.com/docker/docker/api/types/versions" 10 ) 11 12 // ContainerRestart stops and starts a container again. 13 // It makes the daemon wait for the container to be up again for 14 // a specific amount of time, given the timeout. 15 func (cli *Client) ContainerRestart(ctx context.Context, containerID string, options container.StopOptions) error { 16 query := url.Values{} 17 if options.Timeout != nil { 18 query.Set("t", strconv.Itoa(*options.Timeout)) 19 } 20 if options.Signal != "" { 21 // Make sure we negotiated (if the client is configured to do so), 22 // as code below contains API-version specific handling of options. 23 // 24 // Normally, version-negotiation (if enabled) would not happen until 25 // the API request is made. 26 cli.checkVersion(ctx) 27 if versions.GreaterThanOrEqualTo(cli.version, "1.42") { 28 query.Set("signal", options.Signal) 29 } 30 } 31 resp, err := cli.post(ctx, "/containers/"+containerID+"/restart", query, nil, nil) 32 ensureReaderClosed(resp) 33 return err 34 }