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