docker

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 8, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const APIVersion = "v1.44"

APIVersion is the Engine API version the agent speaks (Docker 25+).

View Source
const DefaultSocket = "/var/run/docker.sock"

Variables

This section is empty.

Functions

func IsNotFound

func IsNotFound(err error) bool

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func New

func New(socket string) *Client

func (*Client) Create

func (c *Client) Create(ctx context.Context, name string, req CreateRequest) (string, error)

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

func (c *Client) EnsureNetwork(ctx context.Context, name string, labels map[string]string) error

EnsureNetwork creates a bridge network if it doesn't exist.

func (*Client) Events

func (c *Client) Events(ctx context.Context, label string) (<-chan Event, <-chan error)

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

func (c *Client) ExecExitCode(ctx context.Context, execID string) (int, bool, error)

ExecExitCode returns the exit code once the command finished.

func (*Client) ExecResize

func (c *Client) ExecResize(ctx context.Context, execID string, cols, rows uint32) error

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 (c *Client) ImageExists(ctx context.Context, ref string) (bool, error)

func (*Client) Inspect

func (c *Client) Inspect(ctx context.Context, id string) (ContainerJSON, error)

func (*Client) List

func (c *Client) List(ctx context.Context, labels ...string) ([]ContainerSummary, error)

List returns all containers (running or not) that have every given label.

func (*Client) Logs

func (c *Client) Logs(ctx context.Context, id string, since time.Time, fn func(LogEntry)) error

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

func (c *Client) PruneImages(ctx context.Context, olderThan time.Duration) (uint64, error)

PruneImages removes images no container uses that were created more than olderThan ago, and returns the space reclaimed.

func (*Client) Pull

func (c *Client) Pull(ctx context.Context, ref, registryAuth string) error

Pull pulls ref ("name:tag" or "name@digest"). registryAuth is the base64url-encoded JSON auth config, or "" for anonymous pulls.

func (*Client) Remove

func (c *Client) Remove(ctx context.Context, id string) error

func (*Client) RemoveNetwork

func (c *Client) RemoveNetwork(ctx context.Context, name string) error

RemoveNetwork deletes a network (no error if it does not exist).

func (*Client) RemoveVolume

func (c *Client) RemoveVolume(ctx context.Context, name string) error

RemoveVolume deletes a named volume (no error if it does not exist).

func (*Client) RemoveVolumes

func (c *Client) RemoveVolumes(ctx context.Context, label string) (int, error)

RemoveVolumes deletes the volumes carrying label (key=value).

func (*Client) Start

func (c *Client) Start(ctx context.Context, id string) error

func (*Client) Stats

func (c *Client) Stats(ctx context.Context, id string) (Stats, error)

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) Stop

func (c *Client) Stop(ctx context.Context, id string, timeout time.Duration) error

func (*Client) Version

func (c *Client) Version(ctx context.Context) (string, error)

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"`
}

type ContainerState

type ContainerState struct {
	Status    string `json:"Status"`
	Running   bool   `json:"Running"`
	ExitCode  int    `json:"ExitCode"`
	Error     string `json:"Error"`
	StartedAt string `json:"StartedAt"`
	Health    *struct {
		Status string `json:"Status"`
	} `json:"Health"`
}

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 Error

type Error struct {
	Status  int
	Message string
}

Error is an Engine API error response.

func (*Error) Error

func (e *Error) Error() string

type Event

type Event struct {
	Type   string `json:"Type"`
	Action string `json:"Action"`
	Actor  struct {
		ID         string            `json:"ID"`
		Attributes map[string]string `json:"Attributes"`
	} `json:"Actor"`
}

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"`
	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 LogConfig

type LogConfig struct {
	Type   string            `json:"Type"`
	Config map[string]string `json:"Config,omitempty"`
}

type LogEntry

type LogEntry struct {
	Time   time.Time
	Stream string // stdout | stderr
	Line   string
}

LogEntry is one line of container output.

type Mount

type Mount struct {
	Type     string `json:"Type"` // volume | bind
	Source   string `json:"Source"`
	Target   string `json:"Target"`
	ReadOnly bool   `json:"ReadOnly"`
}

type NetworkingConfig

type NetworkingConfig struct {
	EndpointsConfig map[string]EndpointSettings `json:"EndpointsConfig"`
}

type PortBinding

type PortBinding struct {
	HostIP   string `json:"HostIp"`
	HostPort string `json:"HostPort"`
}

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).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL