docker

package
v0.3.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: AGPL-3.0 Imports: 11 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 a unix socket, built on the standard library only.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("docker: not found")

ErrNotFound is returned for missing containers or images.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Status  int
	Message string
}

APIError is a non-2xx answer from the engine.

func (*APIError) Error

func (e *APIError) Error() string

type Client

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

Client talks to the Docker Engine API.

func New

func New(socketPath string) *Client

New returns a client for the Docker Engine listening on the given unix socket.

func (*Client) Attach

func (c *Client) Attach(ctx context.Context, id string) (io.ReadWriteCloser, error)

Attach connects to a TTY container's stdin/stdout. Reads return the raw output stream; writes go to the process's stdin. Close the connection to detach.

func (*Client) BridgeGateway

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

BridgeGateway returns the gateway IP of Docker's default bridge network (usually 172.17.0.1), which containers use to reach services on the host ({{config.docker.interface}} in eggs).

func (*Client) CreateContainer

func (c *Client) CreateContainer(ctx context.Context, name string, cfg ContainerConfig) (string, error)

CreateContainer creates a container and returns its ID.

func (*Client) EnsureImage

func (c *Client) EnsureImage(ctx context.Context, ref string, progress func(string)) error

EnsureImage pulls ref unless it is already present.

func (*Client) ImageExists

func (c *Client) ImageExists(ctx context.Context, ref string) (bool, error)

ImageExists reports whether an image is present locally.

func (*Client) InspectContainer

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

InspectContainer returns a container's state; ErrNotFound if it does not exist.

func (*Client) KillContainer

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

KillContainer sends a signal (e.g. "SIGKILL", "SIGINT") to the container's main process.

func (*Client) ListContainers

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

ListContainers lists all containers (running or not) carrying a label key=value.

func (*Client) Logs

func (c *Client) Logs(ctx context.Context, id string, tail int) (string, error)

Logs returns the last lines of a TTY container's output.

func (*Client) Ping

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

Ping checks that the engine is reachable and returns its API version.

func (*Client) PullImage

func (c *Client) PullImage(ctx context.Context, ref string, progress func(string)) error

PullImage downloads an image. Progress lines are passed to progress (may be nil).

func (*Client) RemoveContainer

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

RemoveContainer force-removes a container (and anonymous volumes). Missing containers are not an error.

func (*Client) StartContainer

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

StartContainer starts a created container.

func (*Client) Stats

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

Stats takes a single resource sample without waiting for a second one (one-shot). CPU percentage needs two samples; the caller keeps the previous one.

func (*Client) Version

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

Version returns the Docker Engine version (e.g. "29.1.3").

func (*Client) WaitContainer

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

WaitContainer blocks until the container stops and returns its exit code.

type ContainerConfig

type ContainerConfig struct {
	Image        string              `json:"Image"`
	Cmd          []string            `json:"Cmd,omitempty"`
	Entrypoint   []string            `json:"Entrypoint,omitempty"`
	Env          []string            `json:"Env,omitempty"`
	User         string              `json:"User,omitempty"`
	WorkingDir   string              `json:"WorkingDir,omitempty"`
	Tty          bool                `json:"Tty"`
	OpenStdin    bool                `json:"OpenStdin"`
	StdinOnce    bool                `json:"StdinOnce"`
	AttachStdin  bool                `json:"AttachStdin"`
	AttachStdout bool                `json:"AttachStdout"`
	AttachStderr bool                `json:"AttachStderr"`
	Labels       map[string]string   `json:"Labels,omitempty"`
	ExposedPorts map[string]struct{} `json:"ExposedPorts,omitempty"`
	HostConfig   HostConfig          `json:"HostConfig"`
}

ContainerConfig is the subset of the engine's create body the agent uses.

type ContainerState

type ContainerState struct {
	Running  bool   `json:"Running"`
	ExitCode int    `json:"ExitCode"`
	Status   string `json:"Status"`
	OOMKill  bool   `json:"OOMKilled"`
}

ContainerState is the part of inspect the agent needs.

type ContainerSummary

type ContainerSummary struct {
	ID     string            `json:"Id"`
	Names  []string          `json:"Names"`
	State  string            `json:"State"`
	Labels map[string]string `json:"Labels"`
}

ContainerSummary is one entry of ListContainers.

type HostConfig

type HostConfig struct {
	Binds          []string                 `json:"Binds,omitempty"`
	PortBindings   map[string][]PortBinding `json:"PortBindings,omitempty"`
	Memory         int64                    `json:"Memory,omitempty"`
	MemorySwap     int64                    `json:"MemorySwap,omitempty"`
	NanoCPUs       int64                    `json:"NanoCpus,omitempty"`
	PidsLimit      int64                    `json:"PidsLimit,omitempty"`
	CapDrop        []string                 `json:"CapDrop,omitempty"`
	SecurityOpt    []string                 `json:"SecurityOpt,omitempty"`
	Tmpfs          map[string]string        `json:"Tmpfs,omitempty"`
	ReadonlyRootfs bool                     `json:"ReadonlyRootfs"`
	Init           *bool                    `json:"Init,omitempty"`
	LogConfig      *LogConfig               `json:"LogConfig,omitempty"`
}

HostConfig holds limits, mounts and ports.

type LogConfig

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

LogConfig selects the container log driver.

type PortBinding

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

PortBinding maps a container port to a host IP:port.

type StatsSample

type StatsSample struct {
	CPUTotal    uint64 // container CPU time, ns
	SystemTotal uint64 // host CPU time, ns
	OnlineCPUs  int
	MemoryUsed  uint64 // usage minus page cache, like `docker stats`
	MemoryLimit uint64
	NetRx       uint64
	NetTx       uint64
}

StatsSample is one reading of a container's resource usage.

Jump to

Keyboard shortcuts

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