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"
|
|
|
|
"io/ioutil"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
// VolumeInspect returns the information about a specific volume in the docker host.
|
|
|
|
func (cli *Client) VolumeInspect(ctx context.Context, volumeID string) (types.Volume, error) {
|
|
|
|
volume, _, err := cli.VolumeInspectWithRaw(ctx, volumeID)
|
|
|
|
return volume, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// VolumeInspectWithRaw returns the information about a specific volume in the docker host and its raw representation
|
|
|
|
func (cli *Client) VolumeInspectWithRaw(ctx context.Context, volumeID string) (types.Volume, []byte, error) {
|
2017-09-07 17:46:23 +00:00
|
|
|
if volumeID == "" {
|
2017-09-08 16:04:34 +00:00
|
|
|
return types.Volume{}, nil, objectNotFoundError{object: "volume", id: volumeID}
|
2017-09-07 17:46:23 +00:00
|
|
|
}
|
|
|
|
|
2016-09-06 18:46:37 +00:00
|
|
|
var volume types.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 {
|
2017-09-08 16:04:34 +00:00
|
|
|
return volume, nil, wrapResponseError(err, resp, "volume", volumeID)
|
2016-09-06 18:46:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
body, err := ioutil.ReadAll(resp.body)
|
|
|
|
if err != nil {
|
|
|
|
return volume, nil, err
|
|
|
|
}
|
|
|
|
rdr := bytes.NewReader(body)
|
|
|
|
err = json.NewDecoder(rdr).Decode(&volume)
|
|
|
|
return volume, body, err
|
|
|
|
}
|