github.com/tonistiigi/docker@v0.10.1-0.20240229224939-974013b0dc6a/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 if err := cli.checkVersion(ctx); err != nil { 27 return err 28 } 29 if versions.GreaterThanOrEqualTo(cli.version, "1.42") { 30 query.Set("signal", options.Signal) 31 } 32 } 33 resp, err := cli.post(ctx, "/containers/"+containerID+"/restart", query, nil, nil) 34 ensureReaderClosed(resp) 35 return err 36 }