2018-02-05 21:05:59 +00:00
|
|
|
package client // import "github.com/docker/docker/client"
|
2016-09-06 18:46:37 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2018-04-19 22:30:59 +00:00
|
|
|
"context"
|
2016-09-06 18:46:37 +00:00
|
|
|
"encoding/json"
|
2021-08-24 10:10:50 +00:00
|
|
|
"io"
|
2016-09-06 18:46:37 +00:00
|
|
|
|
2022-03-18 15:33:43 +00:00
|
|
|
"github.com/docker/docker/api/types/volume"
|
2016-09-06 18:46:37 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// VolumeInspect returns the information about a specific volume in the docker host.
|
2022-03-18 15:33:43 +00:00
|
|
|
func (cli *Client) VolumeInspect(ctx context.Context, volumeID string) (volume.Volume, error) {
|
|
|
|
vol, _, err := cli.VolumeInspectWithRaw(ctx, volumeID)
|
|
|
|
return vol, err
|
2016-09-06 18:46:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// VolumeInspectWithRaw returns the information about a specific volume in the docker host and its raw representation
|
2022-03-18 15:33:43 +00:00
|
|
|
func (cli *Client) VolumeInspectWithRaw(ctx context.Context, volumeID string) (volume.Volume, []byte, error) {
|
2017-09-07 17:46:23 +00:00
|
|
|
if volumeID == "" {
|
2022-03-18 15:33:43 +00:00
|
|
|
return volume.Volume{}, nil, objectNotFoundError{object: "volume", id: volumeID}
|
2017-09-07 17:46:23 +00:00
|
|
|
}
|
|
|
|
|
2022-03-18 15:33:43 +00:00
|
|
|
var vol volume.Volume
|
2018-01-30 12:35:22 +00:00
|
|
|
resp, err := cli.get(ctx, "/volumes/"+volumeID, nil, nil)
|
2019-02-11 12:26:12 +00:00
|
|
|
defer ensureReaderClosed(resp)
|
2016-09-06 18:46:37 +00:00
|
|
|
if err != nil {
|
2022-03-18 15:33:43 +00:00
|
|
|
return vol, nil, err
|
2016-09-06 18:46:37 +00:00
|
|
|
}
|
|
|
|
|
2021-08-24 10:10:50 +00:00
|
|
|
body, err := io.ReadAll(resp.body)
|
2016-09-06 18:46:37 +00:00
|
|
|
if err != nil {
|
2022-03-18 15:33:43 +00:00
|
|
|
return vol, nil, err
|
2016-09-06 18:46:37 +00:00
|
|
|
}
|
|
|
|
rdr := bytes.NewReader(body)
|
2022-03-18 15:33:43 +00:00
|
|
|
err = json.NewDecoder(rdr).Decode(&vol)
|
|
|
|
return vol, body, err
|
2016-09-06 18:46:37 +00:00
|
|
|
}
|