Documentation
¶
Overview ¶
Package docker is a minimal Docker Engine API client over the local unix socket: only what the agent needs. Using the API directly keeps the agent a small static binary without the Docker SDK's dependency tree.
Index ¶
- Constants
- func IsNotFound(err error) bool
- type Client
- func (c *Client) Clean(ctx context.Context, r dockerusage.CleanRequest) (dockerusage.CleanResult, error)
- func (c *Client) Create(ctx context.Context, name string, req CreateRequest) (string, error)
- func (c *Client) EnsureBridge(ctx context.Context, name, subnet, gateway string, ...) error
- func (c *Client) EnsureNetwork(ctx context.Context, name string, labels map[string]string) error
- func (c *Client) Events(ctx context.Context, label string) (<-chan Event, <-chan error)
- func (c *Client) ExecCreate(ctx context.Context, containerID string, cmd []string, tty bool) (string, error)
- func (c *Client) ExecExitCode(ctx context.Context, execID string) (int, bool, error)
- func (c *Client) ExecResize(ctx context.Context, execID string, cols, rows uint32) error
- func (c *Client) ExecStart(ctx context.Context, execID string, tty bool) (net.Conn, *bufio.Reader, error)
- func (c *Client) ImageExists(ctx context.Context, ref string) (bool, error)
- func (c *Client) Inspect(ctx context.Context, id string) (ContainerJSON, error)
- func (c *Client) List(ctx context.Context, labels ...string) ([]ContainerSummary, error)
- func (c *Client) Logs(ctx context.Context, id string, since time.Time, fn func(LogEntry)) error
- func (c *Client) PruneImages(ctx context.Context, olderThan time.Duration) (uint64, error)
- func (c *Client) Pull(ctx context.Context, ref, registryAuth string) error
- func (c *Client) PullInfo(ctx context.Context, ref, registryAuth string) (PullResult, error)
- func (c *Client) Remove(ctx context.Context, id string) error
- func (c *Client) RemoveNetwork(ctx context.Context, name string) error
- func (c *Client) RemoveVolume(ctx context.Context, name string) error
- func (c *Client) RemoveVolumes(ctx context.Context, label string) (int, error)
- func (c *Client) Start(ctx context.Context, id string) error
- func (c *Client) Stats(ctx context.Context, id string) (Stats, error)
- func (c *Client) Stop(ctx context.Context, id string, timeout time.Duration) error
- func (c *Client) Tail(ctx context.Context, id string, n int) ([]LogEntry, error)
- func (c *Client) Update(ctx context.Context, id string, r Resources) error
- func (c *Client) Usage(ctx context.Context) (dockerusage.Usage, error)
- func (c *Client) Version(ctx context.Context) (string, error)
- type ContainerJSON
- type ContainerState
- type ContainerSummary
- type CreateRequest
- type EndpointSettings
- type Error
- type Event
- type HostConfig
- type LogConfig
- type LogEntry
- type Mount
- type NetworkingConfig
- type PortBinding
- type PullResult
- type Resources
- type RestartPolicy
- type Stats
Constants ¶
const APIVersion = "v1.44"
APIVersion is the Engine API version the agent speaks (Docker 25+).
const DefaultSocket = "/var/run/docker.sock"
Variables ¶
This section is empty.
Functions ¶
func IsNotFound ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) Clean ¶ added in v0.3.2
func (c *Client) Clean(ctx context.Context, r dockerusage.CleanRequest) (dockerusage.CleanResult, error)
Clean removes the objects of r (see dockerusage.CleanRequest). Bulk prunes never touch SynCloud's own containers or named volumes.
func (*Client) EnsureBridge ¶
func (c *Client) EnsureBridge(ctx context.Context, name, subnet, gateway string, options, labels map[string]string) error
EnsureBridge makes sure a bridge network exists with exactly this subnet. A network with a different subnet is recreated if no containers use it.
func (*Client) EnsureNetwork ¶
EnsureNetwork creates a bridge network if it doesn't exist.
func (*Client) Events ¶
Events streams container events for containers with the given label until ctx ends or the connection drops (the error is sent on the returned channel).
func (*Client) ExecCreate ¶
func (c *Client) ExecCreate(ctx context.Context, containerID string, cmd []string, tty bool) (string, error)
ExecCreate prepares a command in a running container.
func (*Client) ExecExitCode ¶
ExecExitCode returns the exit code once the command finished.
func (*Client) ExecResize ¶
ExecResize sets the TTY size.
func (*Client) ExecStart ¶
func (c *Client) ExecStart(ctx context.Context, execID string, tty bool) (net.Conn, *bufio.Reader, error)
ExecStart starts an exec and returns the hijacked connection: writes go to the command's stdin; reads return its output (raw with a TTY, otherwise multiplexed like container logs).
func (*Client) ImageExists ¶
func (*Client) Logs ¶
Logs follows a container's output from since (exclusive) until the container stops or ctx ends. Lines longer than 64 KiB are split.
func (*Client) PruneImages ¶
PruneImages removes images no container uses that were created more than olderThan ago, and returns the space reclaimed.
func (*Client) Pull ¶
Pull pulls ref ("name:tag" or "name@digest"). registryAuth is the base64url-encoded JSON auth config, or "" for anonymous pulls.
func (*Client) RemoveNetwork ¶
RemoveNetwork deletes a network (no error if it does not exist).
func (*Client) RemoveVolume ¶
RemoveVolume deletes a named volume (no error if it does not exist).
func (*Client) RemoveVolumes ¶
RemoveVolumes deletes the volumes carrying label (key=value).
func (*Client) Stats ¶
Stats takes a single sample without waiting for a second one (one-shot), so CPU usage must be derived from consecutive samples by the caller.
func (*Client) Update ¶ added in v0.1.5
Update changes a running container's resources in place, without a restart.
func (*Client) Usage ¶ added in v0.3.2
Usage measures what Docker holds: images, containers (with their log files), volumes and build cache, and the disk they live on. It answers from endpoints that return at once; the sizes of volumes and of container layers, which take a directory walk, are measured in the background and show up as they finish (Usage.Pending counts the ones still running).
type ContainerJSON ¶
type ContainerJSON struct {
ID string `json:"Id"`
Name string `json:"Name"`
State ContainerState `json:"State"`
Config struct {
Image string `json:"Image"`
Labels map[string]string `json:"Labels"`
} `json:"Config"`
NetworkSettings struct {
Networks map[string]struct {
IPAddress string `json:"IPAddress"`
} `json:"Networks"`
} `json:"NetworkSettings"`
HostConfig struct {
CPUShares int64 `json:"CpuShares"`
MemoryReservation int64 `json:"MemoryReservation"`
} `json:"HostConfig"`
}
type ContainerState ¶
type ContainerSummary ¶
type ContainerSummary struct {
ID string `json:"Id"`
Names []string `json:"Names"`
Image string `json:"Image"`
State string `json:"State"` // created, running, exited, …
Labels map[string]string `json:"Labels"`
// NetworkSettings holds each network's address (running containers).
NetworkSettings *struct {
Networks map[string]struct {
IPAddress string `json:"IPAddress"`
} `json:"Networks"`
} `json:"NetworkSettings"`
}
type CreateRequest ¶
type CreateRequest struct {
Image string `json:"Image"`
Entrypoint []string `json:"Entrypoint,omitempty"`
Cmd []string `json:"Cmd,omitempty"`
Env []string `json:"Env,omitempty"`
Labels map[string]string `json:"Labels,omitempty"`
ExposedPorts map[string]struct{} `json:"ExposedPorts,omitempty"`
HostConfig HostConfig `json:"HostConfig"`
// NetworkingConfig sets the container's aliases on its network.
NetworkingConfig *NetworkingConfig `json:"NetworkingConfig,omitempty"`
}
CreateRequest is the subset of the container create body the agent uses.
type EndpointSettings ¶
type EndpointSettings struct {
Aliases []string `json:"Aliases,omitempty"`
}
type HostConfig ¶
type HostConfig struct {
NetworkMode string `json:"NetworkMode,omitempty"`
PortBindings map[string][]PortBinding `json:"PortBindings,omitempty"`
Mounts []Mount `json:"Mounts,omitempty"`
RestartPolicy RestartPolicy `json:"RestartPolicy"`
Memory int64 `json:"Memory,omitempty"`
NanoCPUs int64 `json:"NanoCpus,omitempty"`
// MemoryReservation is the soft limit kept for the container under
// memory pressure.
MemoryReservation int64 `json:"MemoryReservation,omitempty"`
ExtraHosts []string `json:"ExtraHosts,omitempty"`
DNS []string `json:"Dns,omitempty"`
Privileged bool `json:"Privileged,omitempty"`
DNSSearch []string `json:"DnsSearch,omitempty"`
LogConfig LogConfig `json:"LogConfig"`
}
type NetworkingConfig ¶
type NetworkingConfig struct {
EndpointsConfig map[string]EndpointSettings `json:"EndpointsConfig"`
}
type PortBinding ¶
type PullResult ¶ added in v0.2.4
type PullResult struct {
Digest string // sha256:… of the manifest ("" when Docker did not say)
Downloaded int // layers fetched
Cached int // layers already on the node
Bytes int64 // compressed size of the fetched layers
}
PullResult summarizes a finished pull from its progress stream.
type Resources ¶ added in v0.1.5
type Resources struct {
MemoryReservation int64 `json:"MemoryReservation"`
}
Resources are the limits Docker changes on a running container.
type RestartPolicy ¶
type RestartPolicy struct {
Name string `json:"Name"`
}
type Stats ¶
type Stats struct {
Read time.Time `json:"read"`
CPUStats struct {
CPUUsage struct {
TotalUsage uint64 `json:"total_usage"`
} `json:"cpu_usage"`
SystemUsage uint64 `json:"system_cpu_usage"`
OnlineCPUs uint32 `json:"online_cpus"`
} `json:"cpu_stats"`
MemoryStats struct {
Usage uint64 `json:"usage"`
Limit uint64 `json:"limit"`
Stats map[string]uint64 `json:"stats"`
} `json:"memory_stats"`
Networks map[string]struct {
RxBytes uint64 `json:"rx_bytes"`
TxBytes uint64 `json:"tx_bytes"`
} `json:"networks"`
BlkioStats struct {
IOServiceBytesRecursive []struct {
Op string `json:"op"`
Value uint64 `json:"value"`
} `json:"io_service_bytes_recursive"`
} `json:"blkio_stats"`
}
Stats is one sample of a container's resource usage (GET /containers/{id}/stats).