volume_inspect.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. package client // import "github.com/docker/docker/client"
  2. import (
  3. "bytes"
  4. "context"
  5. "encoding/json"
  6. "io"
  7. "github.com/docker/docker/api/types/volume"
  8. )
  9. // VolumeInspect returns the information about a specific volume in the docker host.
  10. func (cli *Client) VolumeInspect(ctx context.Context, volumeID string) (volume.Volume, error) {
  11. vol, _, err := cli.VolumeInspectWithRaw(ctx, volumeID)
  12. return vol, err
  13. }
  14. // VolumeInspectWithRaw returns the information about a specific volume in the docker host and its raw representation
  15. func (cli *Client) VolumeInspectWithRaw(ctx context.Context, volumeID string) (volume.Volume, []byte, error) {
  16. if volumeID == "" {
  17. return volume.Volume{}, nil, objectNotFoundError{object: "volume", id: volumeID}
  18. }
  19. var vol volume.Volume
  20. resp, err := cli.get(ctx, "/volumes/"+volumeID, nil, nil)
  21. defer ensureReaderClosed(resp)
  22. if err != nil {
  23. return vol, nil, err
  24. }
  25. body, err := io.ReadAll(resp.body)
  26. if err != nil {
  27. return vol, nil, err
  28. }
  29. rdr := bytes.NewReader(body)
  30. err = json.NewDecoder(rdr).Decode(&vol)
  31. return vol, body, err
  32. }