wait.go 571 B

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