Documentation
¶
Overview ¶
Package docker is a small Docker Engine API client built on the standard library. It implements only the calls the Agent uses, pinned to one API version, so the most privileged component carries no large SDK.
Index ¶
- Constants
- Variables
- func IsConflict(err error) bool
- func IsNotFound(err error) bool
- type Client
- func (c *Client) ContainerCreate(ctx context.Context, name string, cfg ContainerConfig) (string, error)
- func (c *Client) ContainerInspect(ctx context.Context, id string) (ContainerInfo, error)
- func (c *Client) ContainerList(ctx context.Context, label string) ([]ContainerSummary, error)
- func (c *Client) ContainerRemove(ctx context.Context, id string) error
- func (c *Client) ContainerStart(ctx context.Context, id string) error
- func (c *Client) ContainerStop(ctx context.Context, id string, timeout time.Duration) error
- func (c *Client) CopyFromContainer(ctx context.Context, id, path string) (io.ReadCloser, error)
- func (c *Client) CopyToContainer(ctx context.Context, id, dir string, archive io.Reader) error
- func (c *Client) ImageExists(ctx context.Context, ref string) (bool, error)
- func (c *Client) ImagePull(ctx context.Context, ref string) error
- func (c *Client) Info(ctx context.Context) (Info, error)
- func (c *Client) Logs(ctx context.Context, id string, tail int, follow bool) (io.ReadCloser, error)
- func (c *Client) NetworkConnect(ctx context.Context, network, container string) error
- func (c *Client) NetworkEnsure(ctx context.Context, name string, labels map[string]string) error
- func (c *Client) Output(ctx context.Context, id string, limit int64) (stdout, stderr []byte, err error)
- func (c *Client) Ping(ctx context.Context) error
- func (c *Client) Stats(ctx context.Context, id string) (Stats, error)
- func (c *Client) VolumeCreate(ctx context.Context, name string, labels map[string]string) error
- func (c *Client) VolumeExists(ctx context.Context, name string) (bool, error)
- func (c *Client) VolumeRemove(ctx context.Context, name string) error
- func (c *Client) Wait(ctx context.Context, id string) (int, error)
- func (c *Client) WriteStdin(ctx context.Context, id string, data []byte) error
- type ContainerConfig
- type ContainerInfo
- type ContainerSummary
- type Error
- type HostConfig
- type Info
- type LogConfig
- type Mount
- type PortBinding
- type RestartPolicy
- type Stats
Constants ¶
const APIVersion = "1.44"
APIVersion is the Engine API version the Agent speaks (Docker 25 and later).
Variables ¶
var ErrNotRunning = errors.New("the container is not running")
ErrNotRunning is returned when writing to a container that is not running; Docker would accept the write and drop it.
Functions ¶
func IsConflict ¶
IsConflict reports whether err is a 409 from the Engine.
func IsNotFound ¶
IsNotFound reports whether err is a 404 from the Engine.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to one Engine.
func (*Client) ContainerCreate ¶
func (c *Client) ContainerCreate(ctx context.Context, name string, cfg ContainerConfig) (string, error)
ContainerCreate creates a container and returns its ID.
func (*Client) ContainerInspect ¶
ContainerInspect returns a container's state.
func (*Client) ContainerList ¶
ContainerList lists all containers (running or not) carrying label ("key=value" or "key").
func (*Client) ContainerRemove ¶
ContainerRemove removes a container, stopping it first.
func (*Client) ContainerStart ¶
ContainerStart starts a container; starting a running one is a no-op.
func (*Client) ContainerStop ¶
ContainerStop stops a container, killing it after timeout.
func (*Client) CopyFromContainer ¶ added in v1.12.0
CopyFromContainer returns a tar archive of path in a container's file system (it works on containers that never started). Symlinks are resolved within the container, never on the host.
func (*Client) CopyToContainer ¶ added in v1.11.0
CopyToContainer extracts a tar archive into a container's file system at dir. It works on stopped containers, and into their volumes even when the root file system is read-only.
func (*Client) ImageExists ¶
ImageExists reports whether ref is present locally.
func (*Client) Logs ¶ added in v1.12.0
Logs streams a container's output: the last tail lines, then, with follow, new output until ctx ends or the container stops. Docker's stream framing is removed; stdout and stderr are interleaved in order.
func (*Client) NetworkConnect ¶
NetworkConnect attaches a container to a network; attaching twice is a no-op.
func (*Client) NetworkEnsure ¶
NetworkEnsure creates a bridge network unless it exists.
func (*Client) Output ¶ added in v1.12.0
func (c *Client) Output(ctx context.Context, id string, limit int64) (stdout, stderr []byte, err error)
Output returns a stopped container's complete stdout and stderr, each cut off at limit bytes.
func (*Client) VolumeCreate ¶
VolumeCreate creates a named volume; creating an existing one is a no-op.
func (*Client) VolumeExists ¶
VolumeExists reports whether a volume exists.
func (*Client) VolumeRemove ¶
VolumeRemove removes a volume.
type ContainerConfig ¶
type ContainerConfig struct {
Image string `json:"Image"`
Entrypoint []string `json:"Entrypoint,omitempty"`
Cmd []string `json:"Cmd,omitempty"`
WorkingDir string `json:"WorkingDir,omitempty"`
// OpenStdin keeps stdin open for the console.
OpenStdin bool `json:"OpenStdin,omitempty"`
Env []string `json:"Env,omitempty"`
User string `json:"User,omitempty"`
Labels map[string]string `json:"Labels,omitempty"`
ExposedPorts map[string]struct{} `json:"ExposedPorts,omitempty"`
HostConfig HostConfig `json:"HostConfig"`
}
ContainerConfig is the body of a container create request. Field names follow the Engine API.
type ContainerInfo ¶
type ContainerInfo struct {
ID string `json:"Id"`
Name string `json:"Name"`
Config struct {
Image string `json:"Image"`
Labels map[string]string `json:"Labels"`
User string `json:"User"`
WorkingDir string `json:"WorkingDir"`
Cmd []string `json:"Cmd"`
} `json:"Config"`
State struct {
Status string `json:"Status"`
Running bool `json:"Running"`
ExitCode int `json:"ExitCode"`
OOMKilled bool `json:"OOMKilled"`
StartedAt time.Time `json:"StartedAt"`
FinishedAt time.Time `json:"FinishedAt"`
} `json:"State"`
HostConfig HostConfig `json:"HostConfig"`
NetworkSettings struct {
Networks map[string]struct {
IPAddress string `json:"IPAddress"`
} `json:"Networks"`
} `json:"NetworkSettings"`
}
ContainerInfo is the part of an inspect answer the Agent uses.
type ContainerSummary ¶
type ContainerSummary struct {
ID string `json:"Id"`
Names []string `json:"Names"`
Labels map[string]string `json:"Labels"`
State string `json:"State"`
}
ContainerSummary is one entry of a container list.
type HostConfig ¶
type HostConfig struct {
NanoCPUs int64 `json:"NanoCpus,omitempty"`
Memory int64 `json:"Memory,omitempty"`
MemorySwap int64 `json:"MemorySwap,omitempty"`
PidsLimit *int64 `json:"PidsLimit,omitempty"`
CapDrop []string `json:"CapDrop,omitempty"`
SecurityOpt []string `json:"SecurityOpt,omitempty"`
ReadonlyRootfs bool `json:"ReadonlyRootfs,omitempty"`
Tmpfs map[string]string `json:"Tmpfs,omitempty"`
Mounts []Mount `json:"Mounts,omitempty"`
PortBindings map[string][]PortBinding `json:"PortBindings,omitempty"`
RestartPolicy RestartPolicy `json:"RestartPolicy"`
LogConfig LogConfig `json:"LogConfig"`
NetworkMode string `json:"NetworkMode,omitempty"`
Init *bool `json:"Init,omitempty"`
}
HostConfig holds the isolation and resource settings of a container.
type Info ¶
type Info struct {
ServerVersion string `json:"ServerVersion"`
}
Info is the part of /info the Agent uses.
type LogConfig ¶
type LogConfig struct {
Type string `json:"Type"`
Config map[string]string `json:"Config,omitempty"`
}
LogConfig selects the log driver.
type Mount ¶
type Mount struct {
Type string `json:"Type"`
Source string `json:"Source"`
Target string `json:"Target"`
}
Mount attaches a volume.
type PortBinding ¶
type PortBinding struct {
HostIP string `json:"HostIp,omitempty"`
HostPort string `json:"HostPort"`
}
PortBinding publishes a container port on the host.
type RestartPolicy ¶
type RestartPolicy struct {
Name string `json:"Name"`
}
RestartPolicy is Docker's own restart policy; the Agent uses "no" and applies the server's policy itself.
type Stats ¶ added in v1.11.0
type Stats struct {
CPUStats struct {
CPUUsage struct {
TotalUsage uint64 `json:"total_usage"`
} `json:"cpu_usage"`
} `json:"cpu_stats"`
MemoryStats struct {
Usage uint64 `json:"usage"`
Stats map[string]uint64 `json:"stats"`
} `json:"memory_stats"`
}
Stats is the part of a container stats sample the Agent reads.
func (Stats) MemoryBytes ¶ added in v1.11.0
MemoryBytes is the memory a container uses, without reclaimable page cache (as docker stats reports it).