github.com/rawahars/moby@v24.0.4+incompatible/client/container_stop.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  // ContainerStop stops a container. In case the container fails to stop
    13  // gracefully within a time frame specified by the timeout argument,
    14  // it is forcefully terminated (killed).
    15  //
    16  // If the timeout is nil, the container's StopTimeout value is used, if set,
    17  // otherwise the engine default. A negative timeout value can be specified,
    18  // meaning no timeout, i.e. no forceful termination is performed.
    19  func (cli *Client) ContainerStop(ctx context.Context, containerID string, options container.StopOptions) error {
    20  	query := url.Values{}
    21  	if options.Timeout != nil {
    22  		query.Set("t", strconv.Itoa(*options.Timeout))
    23  	}
    24  	if options.Signal != "" && versions.GreaterThanOrEqualTo(cli.version, "1.42") {
    25  		query.Set("signal", options.Signal)
    26  	}
    27  	resp, err := cli.post(ctx, "/containers/"+containerID+"/stop", query, nil, nil)
    28  	ensureReaderClosed(resp)
    29  	return err
    30  }