container_stop.go 896 B

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