container_wait.go 629 B

123456789101112131415161718192021222324252627
  1. package client
  2. import (
  3. "encoding/json"
  4. "golang.org/x/net/context"
  5. "github.com/docker/engine-api/types"
  6. )
  7. // ContainerWait pauses execution util a container is exits.
  8. // It returns the API status code as response of its readiness.
  9. func (cli *Client) ContainerWait(ctx context.Context, containerID string) (int, error) {
  10. resp, err := cli.post(ctx, "/containers/"+containerID+"/wait", nil, nil, nil)
  11. if err != nil {
  12. return -1, err
  13. }
  14. defer ensureReaderClosed(resp)
  15. var res types.ContainerWaitResponse
  16. if err := json.NewDecoder(resp.body).Decode(&res); err != nil {
  17. return -1, err
  18. }
  19. return res.StatusCode, nil
  20. }