container_restart.go 644 B

12345678910111213141516171819202122
  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. // ContainerRestart stops and starts a container again.
  9. // It makes the daemon to wait for the container to be up again for
  10. // a specific amount of time, given the timeout.
  11. func (cli *Client) ContainerRestart(ctx context.Context, containerID string, timeout *time.Duration) error {
  12. query := url.Values{}
  13. if timeout != nil {
  14. query.Set("t", timetypes.DurationToSecondsString(*timeout))
  15. }
  16. resp, err := cli.post(ctx, "/containers/"+containerID+"/restart", query, nil, nil)
  17. ensureReaderClosed(resp)
  18. return err
  19. }