github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/engine/client/container_stop.go (about) 1 package client // import "github.com/docker/docker/client" 2 3 import ( 4 "context" 5 "net/url" 6 "time" 7 8 timetypes "github.com/docker/docker/api/types/time" 9 ) 10 11 // ContainerStop stops a container. In case the container fails to stop 12 // gracefully within a time frame specified by the timeout argument, 13 // it is forcefully terminated (killed). 14 // 15 // If the timeout is nil, the container's StopTimeout value is used, if set, 16 // otherwise the engine default. A negative timeout value can be specified, 17 // meaning no timeout, i.e. no forceful termination is performed. 18 func (cli *Client) ContainerStop(ctx context.Context, containerID string, timeout *time.Duration) error { 19 query := url.Values{} 20 if timeout != nil { 21 query.Set("t", timetypes.DurationToSecondsString(*timeout)) 22 } 23 resp, err := cli.post(ctx, "/containers/"+containerID+"/stop", query, nil, nil) 24 ensureReaderClosed(resp) 25 return err 26 }