container_stop.go 609 B

123456789101112131415161718192021
  1. package client
  2. import (
  3. "net/url"
  4. "time"
  5. timetypes "github.com/docker/docker/api/types/time"
  6. "golang.org/x/net/context"
  7. )
  8. // ContainerStop stops a container without terminating the process.
  9. // The process is blocked until the container stops or the timeout expires.
  10. func (cli *Client) ContainerStop(ctx context.Context, containerID string, timeout *time.Duration) error {
  11. query := url.Values{}
  12. if timeout != nil {
  13. query.Set("t", timetypes.DurationToSecondsString(*timeout))
  14. }
  15. resp, err := cli.post(ctx, "/containers/"+containerID+"/stop", query, nil, nil)
  16. ensureReaderClosed(resp)
  17. return err
  18. }