aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/fsouza/go-dockerclient/container_inspect.go
blob: 48c1e8ea7b96831c509596691fd105cdb756bf79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package docker

import (
	"context"
	"encoding/json"
	"errors"
	"net/http"
)

// InspectContainer returns information about a container by its ID.
//
// Deprecated: Use InspectContainerWithOptions instead.
func (c *Client) InspectContainer(id string) (*Container, error) {
	return c.InspectContainerWithOptions(InspectContainerOptions{ID: id})
}

// InspectContainerWithContext returns information about a container by its ID.
// The context object can be used to cancel the inspect request.
//
// Deprecated: Use InspectContainerWithOptions instead.
func (c *Client) InspectContainerWithContext(id string, ctx context.Context) (*Container, error) {
	return c.InspectContainerWithOptions(InspectContainerOptions{ID: id, Context: ctx})
}

// InspectContainerWithOptions returns information about a container by its ID.
//
// See https://goo.gl/FaI5JT for more details.
func (c *Client) InspectContainerWithOptions(opts InspectContainerOptions) (*Container, error) {
	path := "/containers/" + opts.ID + "/json?" + queryString(opts)
	resp, err := c.do(http.MethodGet, path, doOptions{
		context: opts.Context,
	})
	if err != nil {
		var e *Error
		if errors.As(err, &e) && e.Status == http.StatusNotFound {
			return nil, &NoSuchContainer{ID: opts.ID}
		}
		return nil, err
	}
	defer resp.Body.Close()
	var container Container
	if err := json.NewDecoder(resp.Body).Decode(&container); err != nil {
		return nil, err
	}
	return &container, nil
}

// InspectContainerOptions specifies parameters for InspectContainerWithOptions.
//
// See https://goo.gl/FaI5JT for more details.
type InspectContainerOptions struct {
	Context context.Context
	ID      string `qs:"-"`
	Size    bool
}