docker

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 43 Imported by: 0

Documentation

Overview

Package docker manages connections to one or more Docker engines and exposes a domain-shaped API (containers, networks, stats, logs) for the rest of the app. Connections are created lazily per host and cached.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnknownAction = errors.New("docker: unknown container action")

ErrUnknownAction is returned by ContainerAction for unsupported actions.

Functions

func BuildCheckAvailable added in v1.3.0

func BuildCheckAvailable(ctx context.Context) bool

BuildCheckAvailable reports whether `docker build --check` (BuildKit's Dockerfile linter) is usable. Probed once and cached for the process lifetime.

func ComposeAvailable added in v1.2.0

func ComposeAvailable(ctx context.Context) bool

ComposeAvailable reports whether the `docker compose` CLI is usable on the host. The result is probed once and cached for the process lifetime.

func ComposeConfig added in v1.3.0

func ComposeConfig(ctx context.Context, dir, slug string) (string, error)

ComposeConfig validates the project's compose file via `docker compose config --quiet` — the same parser used to deploy, so YAML anchors/aliases, merge keys (`<<`), `${VAR}` interpolation and `extends`/`include` resolve exactly as they will at `up` time. On success it prints nothing; on failure the combined output carries the error (often with a file/line reference).

func ComposeConfigJSON added in v1.3.0

func ComposeConfigJSON(ctx context.Context, dir, slug string) ([]byte, error)

ComposeConfigJSON returns the resolved compose model as JSON (`docker compose config --format json`) — used to build a project overview (services, ports, volumes) and detect issues like duplicate host ports.

func ComposeDown added in v1.2.0

func ComposeDown(ctx context.Context, dir, slug string) (string, error)

ComposeDown runs `docker compose -p <slug> down` in dir (removes containers and the project's networks; named volumes are kept, like the CLI default).

func ComposeProfiles added in v1.2.0

func ComposeProfiles(ctx context.Context, dir, slug string) ([]string, error)

ComposeProfiles lists the profiles defined in the project's compose file (`docker compose config --profiles`), one per line.

func ComposeResolvedConfig added in v1.3.0

func ComposeResolvedConfig(ctx context.Context, dir, slug string) (string, error)

ComposeResolvedConfig returns the fully-resolved compose configuration (`docker compose config` without --quiet): anchors, merge keys, ${VAR} interpolation and extends/include flattened into one canonical YAML — exactly what `up` will deploy. Only stdout (the YAML) is returned; on failure the error carries stderr.

func ComposeRestart added in v1.2.0

func ComposeRestart(ctx context.Context, dir, slug string) (string, error)

ComposeRestart runs `docker compose -p <slug> restart` (restarts the running containers without re-creating them).

func ComposeUp added in v1.2.0

func ComposeUp(ctx context.Context, dir, slug string, profiles []string) (string, error)

ComposeUp runs `docker compose -p <slug> [--profile p…] up -d` in dir and returns the combined stdout+stderr (for display) alongside any error.

func ComposeWarnings added in v1.3.0

func ComposeWarnings(out string) []string

ComposeWarnings extracts the human-readable messages from `level=warning` lines in compose CLI output (e.g. `The "X" variable is not set`), which the CLI prints to stderr even for an otherwise-valid file.

func DockerfileCheck added in v1.3.0

func DockerfileCheck(ctx context.Context, content string) (string, error)

DockerfileCheck lints a Dockerfile with `docker build --check` without running any build steps. The content is written to a throwaway build context (the check doesn't read COPY/ADD sources, so the Dockerfile alone is enough). The cleaned check output is returned with BuildKit progress noise stripped; a non-nil error means the check reported problems — lint warnings (exit 255) or a parse error (exit 1) — with the detail in the returned string.

Types

type BuildMessage

type BuildMessage struct {
	Stream string `json:"stream,omitempty"`
	Error  string `json:"error,omitempty"`
}

BuildMessage is one line of build output forwarded to the UI. Build streams are mostly free-text (Stream); Error carries a build failure.

type BuildOptions

type BuildOptions struct {
	Tags       []string
	Dockerfile string
	NoCache    bool
	BuildArgs  map[string]string
}

BuildOptions are the user-facing knobs for an image build.

type ContainerDetail

type ContainerDetail struct {
	ID            string            `json:"id"`
	Name          string            `json:"name"`
	Image         string            `json:"image"`
	State         string            `json:"state"`
	Status        string            `json:"status"`
	Health        string            `json:"health,omitempty"`
	Created       string            `json:"created"`
	StartedAt     string            `json:"startedAt,omitempty"`
	RestartCount  int               `json:"restartCount"`
	Command       []string          `json:"command"`
	Env           []string          `json:"env"`
	Labels        map[string]string `json:"labels"`
	Mounts        []MountInfo       `json:"mounts"`
	Ports         []PortMapping     `json:"ports"`
	Networks      []NetworkAttach   `json:"networks"`
	RestartPolicy string            `json:"restartPolicy,omitempty"`
}

ContainerDetail is the full inspect view shown on the detail page.

type ContainerSummary

type ContainerSummary struct {
	ID       string            `json:"id"`
	Name     string            `json:"name"`
	Image    string            `json:"image"`
	State    string            `json:"state"`  // running, exited, paused, ...
	Status   string            `json:"status"` // human text, e.g. "Up 3 hours"
	Created  int64             `json:"created"`
	Ports    []PortMapping     `json:"ports"`
	Networks []string          `json:"networks"`
	Labels   map[string]string `json:"labels"`
}

ContainerSummary is a compact view used in lists.

type CreateSpec

type CreateSpec struct {
	Image         string     `json:"image"`
	Name          string     `json:"name"`
	Cmd           []string   `json:"cmd"`
	Env           []string   `json:"env"`   // KEY=VALUE
	Binds         []string   `json:"binds"` // src:dst[:ro]
	Ports         []PortSpec `json:"ports"`
	RestartPolicy string     `json:"restartPolicy"` // "", no, always, unless-stopped, on-failure
	Memory        int64      `json:"memory"`        // bytes, 0 = unset
	NanoCPUs      int64      `json:"nanoCpus"`      // 0 = unset (cpus * 1e9)
	Start         bool       `json:"start"`
}

CreateSpec is the user-facing container create/run request.

type DiffEntry

type DiffEntry struct {
	Kind string `json:"kind"` // modified | added | deleted
	Path string `json:"path"`
}

DiffEntry is one filesystem change in a container relative to its image.

type DiskUsage

type DiskUsage struct {
	LayersSize int64         `json:"layersSize"`
	Images     UsageCategory `json:"images"`
	Containers UsageCategory `json:"containers"`
	Volumes    UsageCategory `json:"volumes"`
	BuildCache UsageCategory `json:"buildCache"`
}

DiskUsage summarises what Docker is storing (docker system df).

type Event

type Event struct {
	Action        string // "die", "start", "stop", "kill", "oom", "health_status: unhealthy", ...
	ContainerID   string
	ContainerName string
	Image         string
	ExitCode      string
}

Event is a simplified container lifecycle event for the monitor/alert engine.

type EventMsg

type EventMsg struct {
	Time   int64             `json:"time"`
	Type   string            `json:"type"`   // container | image | network | volume | …
	Action string            `json:"action"` // start | die | pull | create | …
	ID     string            `json:"id"`
	Name   string            `json:"name"`
	Attr   map[string]string `json:"attr,omitempty"`
}

EventMsg is one Docker daemon event, flattened for the UI.

type ExecSession

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

ExecSession is a live interactive exec attached to a container. It is a bidirectional byte stream (Read = container output, Write = stdin) plus a Resize control. Works for any host kind, since it goes through the Docker API.

func (*ExecSession) Close

func (s *ExecSession) Close()

Close tears down the hijacked connection.

func (*ExecSession) Conn

func (s *ExecSession) Conn() net.Conn

Conn exposes the underlying connection (for setting deadlines if needed).

func (*ExecSession) Read

func (s *ExecSession) Read(p []byte) (int, error)

Read returns container output (stdout+stderr merged, since TTY).

func (*ExecSession) Resize

func (s *ExecSession) Resize(ctx context.Context, cols, rows uint) error

Resize updates the remote TTY dimensions.

func (*ExecSession) Write

func (s *ExecSession) Write(p []byte) (int, error)

Write sends bytes to the exec's stdin.

type FileEntry

type FileEntry struct {
	Name   string `json:"name"`
	IsDir  bool   `json:"isDir"`
	IsLink bool   `json:"isLink"`
	Size   int64  `json:"size"`
	Mode   string `json:"mode"`
	Target string `json:"target,omitempty"` // symlink target
}

FileEntry is one item in a container directory listing.

type HistoryEntry

type HistoryEntry struct {
	ID        string   `json:"id"`
	Created   int64    `json:"created"`
	CreatedBy string   `json:"createdBy"`
	Size      int64    `json:"size"`
	Comment   string   `json:"comment"`
	Tags      []string `json:"tags"`
}

HistoryEntry is one layer in an image's build history.

type HostKeyMismatchError

type HostKeyMismatchError struct {
	Fingerprint string // SHA256:… of the key actually presented now
}

HostKeyMismatchError is returned when the presented key differs from the one we already trust. This is a hard stop: it can mean a reinstalled host — or a man-in-the-middle. We never auto-accept; the operator must re-trust manually.

func (*HostKeyMismatchError) Error

func (e *HostKeyMismatchError) Error() string

type HostKeyUnknownError

type HostKeyUnknownError struct {
	Fingerprint string // SHA256:… of the presented key
	KeyType     string // e.g. "ssh-ed25519"
}

HostKeyUnknownError is returned on first contact with an SSH host whose key is neither pinned in the DB nor present in ~/.ssh/known_hosts. The caller can surface the fingerprint to the operator and, on explicit approval, pin it.

func (*HostKeyUnknownError) Error

func (e *HostKeyUnknownError) Error() string

type HostPortProbe added in v1.1.0

type HostPortProbe struct {
	ContainerID   string `json:"containerId"`
	ContainerName string `json:"containerName"`
	PortProbe
}

HostPortProbe is one published port on the host, tagged with the container that owns it — the rows behind the host-wide "open ports" view.

type ImagePruneResult

type ImagePruneResult struct {
	Deleted        []string `json:"deleted"`
	SpaceReclaimed uint64   `json:"spaceReclaimed"`
}

ImagePruneResult reports what a dangling-image prune removed.

type ImageSummary

type ImageSummary struct {
	ID          string   `json:"id"`
	RepoTags    []string `json:"repoTags"`
	RepoDigests []string `json:"repoDigests"`
	Size        int64    `json:"size"`
	Created     int64    `json:"created"` // unix seconds
	Dangling    bool     `json:"dangling"`
	InUse       bool     `json:"inUse"` // referenced by an existing container
}

ImageSummary is a compact view of a local image for the Images page.

type LogLine

type LogLine struct {
	Stream    string `json:"stream"` // "stdout" | "stderr"
	Message   string `json:"message"`
	Timestamp string `json:"timestamp,omitempty"`
}

LogLine is one line emitted from a container log stream.

type Manager

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

Manager owns Docker client connections keyed by host ID.

func NewManager

func NewManager(s *store.Store) *Manager

NewManager returns a manager that resolves hosts from the store.

func (*Manager) BuildImage

func (m *Manager) BuildImage(ctx context.Context, hostID int64, buildContext io.Reader, opts BuildOptions, onMsg func(BuildMessage)) error

BuildImage builds an image from a tar (optionally gzip'd) build context, streaming the daemon's output line by line. The context reader is supplied by the caller (typically the uploaded request body).

func (*Manager) Client

func (m *Manager) Client(ctx context.Context, hostID int64) (*client.Client, error)

Client returns a connected Docker client for the given host ID, creating and caching it on first use. A hostID <= 0 means "the default local host", which lets clients (REST and WebSocket) omit the host when targeting localhost.

func (*Manager) Close

func (m *Manager) Close()

Close disconnects all cached clients.

func (*Manager) CloseVolumeBrowser added in v1.3.0

func (m *Manager) CloseVolumeBrowser(ctx context.Context, hostID int64, volume string)

CloseVolumeBrowser removes the helper container(s) for a volume (called when the user closes the browser).

func (*Manager) CommitContainer

func (m *Manager) CommitContainer(ctx context.Context, hostID int64, id, ref, comment string) (string, error)

CommitContainer snapshots a container into a new image (reference repo:tag).

func (*Manager) ConnectNetwork added in v1.3.0

func (m *Manager) ConnectNetwork(ctx context.Context, hostID int64, netID, containerID string) error

ConnectNetwork attaches a container to a network.

func (*Manager) ContainerAction

func (m *Manager) ContainerAction(ctx context.Context, hostID int64, id, action string) error

ContainerAction performs a lifecycle action: start, stop, restart, pause, unpause, kill. Unknown actions return an error.

func (*Manager) ContainerDiff

func (m *Manager) ContainerDiff(ctx context.Context, hostID int64, id string) ([]DiffEntry, error)

ContainerDiff lists filesystem changes since the container started.

func (*Manager) ContainerTop

func (m *Manager) ContainerTop(ctx context.Context, hostID int64, id string) (*TopResult, error)

ContainerTop returns the processes running inside a container.

func (*Manager) CopyFrom

func (m *Manager) CopyFrom(ctx context.Context, hostID int64, id, path string) (io.ReadCloser, container.PathStat, error)

CopyFrom streams a path out of a container as a TAR archive along with its stat (so the caller can tell a file from a directory). Caller closes the reader.

func (*Manager) CopyTo

func (m *Manager) CopyTo(ctx context.Context, hostID int64, id, destDir string, content io.Reader) error

CopyTo writes a TAR archive into the container at destDir.

func (*Manager) CreateContainer

func (m *Manager) CreateContainer(ctx context.Context, hostID int64, spec CreateSpec) (string, error)

CreateContainer creates (and optionally starts) a container from a spec.

func (*Manager) CreateNetwork added in v1.3.0

func (m *Manager) CreateNetwork(ctx context.Context, hostID int64, req NetworkCreateRequest) (string, error)

CreateNetwork creates a user-defined network and returns its ID.

func (*Manager) CreateVolume

func (m *Manager) CreateVolume(ctx context.Context, hostID int64, name, driver string, labels map[string]string) (*VolumeSummary, error)

CreateVolume creates a named volume with an optional driver.

func (*Manager) DeletePath

func (m *Manager) DeletePath(ctx context.Context, hostID int64, id, path string) error

DeletePath removes a path inside the container (rm -rf).

func (*Manager) Disconnect

func (m *Manager) Disconnect(hostID int64)

Disconnect drops the cached client for a host (e.g. after it is deleted or reconfigured), so the next use reconnects with fresh settings.

func (*Manager) DisconnectNetwork added in v1.3.0

func (m *Manager) DisconnectNetwork(ctx context.Context, hostID int64, netID, containerID string, force bool) error

DisconnectNetwork detaches a container from a network (force allows removing a running container's endpoint).

func (*Manager) DiskUsage

func (m *Manager) DiskUsage(ctx context.Context, hostID int64) (*DiskUsage, error)

DiskUsage reports how much disk Docker objects occupy (docker system df).

func (*Manager) ExecAttach

func (m *Manager) ExecAttach(ctx context.Context, hostID int64, containerID string, cmd []string, cols, rows uint) (*ExecSession, error)

ExecAttach starts a TTY exec in the container and attaches to it. Pass cmd to override the shell. cols/rows seed the initial terminal size.

func (*Manager) ExportContainer

func (m *Manager) ExportContainer(ctx context.Context, hostID int64, id string) (io.ReadCloser, error)

ExportContainer streams a container's filesystem as a tar archive.

func (*Manager) ImageHistory

func (m *Manager) ImageHistory(ctx context.Context, hostID int64, ref string) ([]HistoryEntry, error)

ImageHistory returns the layer history of an image.

func (*Manager) ImportImage

func (m *Manager) ImportImage(ctx context.Context, hostID int64, tarball io.Reader, ref string) (string, error)

ImportImage creates an image from a filesystem tarball (docker import), tagging it as ref. It returns the daemon's output summary.

func (*Manager) InspectContainer

func (m *Manager) InspectContainer(ctx context.Context, hostID int64, id string) (*ContainerDetail, error)

InspectContainer returns the detailed view of a single container.

func (*Manager) InspectRaw

func (m *Manager) InspectRaw(ctx context.Context, hostID int64, kind, id string) (json.RawMessage, error)

InspectRaw returns the daemon's raw JSON for an object, preserving every field (more faithful than re-marshalling the SDK struct). kind is one of container, image, network, volume.

func (*Manager) ListContainers

func (m *Manager) ListContainers(ctx context.Context, hostID int64) ([]ContainerSummary, error)

ListContainers returns a compact summary of all containers on the host.

func (*Manager) ListImages

func (m *Manager) ListImages(ctx context.Context, hostID int64) ([]ImageSummary, error)

ListImages returns local images, flagging which are untagged ("dangling") and which are referenced by an existing container (so the UI can warn before removing one that is in use).

func (*Manager) ListNetworks

func (m *Manager) ListNetworks(ctx context.Context, hostID int64) ([]NetworkSummary, error)

ListNetworks returns networks plus the set of containers attached to each, which the frontend uses to draw the connectivity topology.

func (*Manager) ListPath

func (m *Manager) ListPath(ctx context.Context, hostID int64, id, path string) ([]FileEntry, error)

ListPath lists one directory level inside a container by running `ls`. It is shell-independent (direct argv) but needs an `ls` binary in the image.

func (*Manager) ListStacks added in v1.2.0

func (m *Manager) ListStacks(ctx context.Context, hostID int64) ([]Stack, error)

ListStacks groups the host's containers into Compose stacks by their `com.docker.compose.project` label. Containers without the label are ignored.

func (*Manager) ListVolumes

func (m *Manager) ListVolumes(ctx context.Context, hostID int64) ([]VolumeSummary, error)

ListVolumes returns all volumes, cross-referencing containers' mounts so the UI can show (and warn about) volumes that are still in use.

func (*Manager) LoadImage

func (m *Manager) LoadImage(ctx context.Context, hostID int64, tar io.Reader) (string, error)

LoadImage loads images from a tar archive (docker save format) and returns the daemon's human-readable summary (e.g. "Loaded image: repo:tag").

func (*Manager) MakeDir added in v1.3.0

func (m *Manager) MakeDir(ctx context.Context, hostID int64, id, path string) error

MakeDir creates a directory inside the container (mkdir -p).

func (*Manager) ProbeContainerPorts added in v1.1.0

func (m *Manager) ProbeContainerPorts(ctx context.Context, hostID int64, containerID string) ([]PortProbe, error)

ProbeContainerPorts actively fingerprints every published TCP port of a container: it connects (locally, or tunnelled through SSH for ssh hosts) and classifies the listener by banner / HTTP / TLS / Redis handshake. UDP and unpublished ports get a passive guess only.

func (*Manager) ProbeHostKey

func (m *Manager) ProbeHostKey(ctx context.Context, hostID int64) (keyLine, fingerprint string, err error)

ProbeHostKey connects to an SSH host and returns its presented public key (authorized_keys line) and SHA256 fingerprint, trusting whatever is offered. It is used only by the explicit trust flow, so the operator can pin a key after reviewing its fingerprint.

func (*Manager) ProbeHostPorts added in v1.1.0

func (m *Manager) ProbeHostPorts(ctx context.Context, hostID int64) ([]HostPortProbe, error)

ProbeHostPorts scans every published port of every running container on the host — the host-wide "open ports" map. Probes run in one bounded pool so a busy host doesn't open a flood of connections at once.

func (*Manager) PruneImages

func (m *Manager) PruneImages(ctx context.Context, hostID int64) (*ImagePruneResult, error)

PruneImages removes dangling images and reports what was reclaimed.

func (*Manager) PruneNetworks added in v1.3.0

func (m *Manager) PruneNetworks(ctx context.Context, hostID int64) ([]string, error)

PruneNetworks removes all unused user-defined networks and returns the names the daemon deleted.

func (*Manager) PruneVolumes

func (m *Manager) PruneVolumes(ctx context.Context, hostID int64) (*VolumePruneResult, error)

PruneVolumes removes all unused (anonymous and named) volumes.

func (*Manager) PullImage

func (m *Manager) PullImage(ctx context.Context, hostID int64, ref string, onProgress func(PullProgress)) error

PullImage pulls a reference and reports progress via onProgress until the stream completes. The Docker daemon emits newline-delimited JSON messages; we decode them and translate to PullProgress. A message carrying an error aborts the pull with that error.

func (*Manager) PushImage

func (m *Manager) PushImage(ctx context.Context, hostID int64, ref string, onProgress func(PullProgress)) error

PushImage pushes a reference to its registry, streaming progress like a pull. Pushing requires credentials for the target registry; without them we fail early with a clear message rather than letting the daemon return a raw 401.

func (*Manager) ReapAllVolumeHelpers added in v1.3.0

func (m *Manager) ReapAllVolumeHelpers(ctx context.Context)

ReapAllVolumeHelpers clears every volume-browser helper on the default host (called at startup to remove orphans from a previous run).

func (*Manager) RegistryLogin

func (m *Manager) RegistryLogin(ctx context.Context, hostID int64, a store.RegistryAuth) error

RegistryLogin verifies a set of credentials against a registry via the daemon.

func (*Manager) RemoveImage

func (m *Manager) RemoveImage(ctx context.Context, hostID int64, ref string, force bool) ([]string, error)

RemoveImage deletes an image by ID or reference. force allows removing an image that is tagged multiple times or referenced by stopped containers. It returns the list of untagged/deleted references for the UI.

func (*Manager) RemoveNetwork

func (m *Manager) RemoveNetwork(ctx context.Context, hostID int64, id string) error

RemoveNetwork deletes a user-defined network. The daemon refuses to remove predefined networks (bridge/host/none) or ones with attached endpoints, and that error is surfaced to the caller.

func (*Manager) RemoveVolume

func (m *Manager) RemoveVolume(ctx context.Context, hostID int64, name string, force bool) error

RemoveVolume deletes a volume. force removes it even if the metadata claims a reference; the daemon still refuses volumes actively mounted by a container.

func (*Manager) RenameContainer

func (m *Manager) RenameContainer(ctx context.Context, hostID int64, id, newName string) error

RenameContainer changes a container's name.

func (*Manager) ResolveHostID added in v1.2.0

func (m *Manager) ResolveHostID(ctx context.Context, hostID int64) (int64, error)

ResolveHostID maps hostID <= 0 to the default local host's ID.

func (*Manager) ResourceOverview added in v1.1.0

func (m *Manager) ResourceOverview(ctx context.Context, hostID int64) (ResourceOverview, error)

ResourceOverview samples every running container and reports each one's share of the host's total CPU and memory. Per-container stats are gathered concurrently (bounded); a container that fails to sample is simply omitted.

func (*Manager) SampleStats

func (m *Manager) SampleStats(ctx context.Context, hostID int64, id string) (StatsSample, error)

SampleStats fetches a single (non-streaming) stats frame and computes one sample. Used by the monitor for periodic polling and the Prometheus exporter.

func (*Manager) SaveImage

func (m *Manager) SaveImage(ctx context.Context, hostID int64, refs []string) (io.ReadCloser, error)

SaveImage streams one or more images as a tar archive (docker save format). The caller is responsible for closing the returned reader.

func (*Manager) StackAction added in v1.2.0

func (m *Manager) StackAction(ctx context.Context, hostID int64, project, action string) error

StackAction applies a lifecycle action to every container in a stack: start / stop / restart, or remove (force-removes the containers and then the project's Compose networks, leaving named volumes intact — like `docker compose down`).

func (*Manager) StackComposeFile added in v1.2.0

func (m *Manager) StackComposeFile(ctx context.Context, hostID int64, project string) (path, content string, err error)

StackComposeFile best-effort reads and returns the stack's compose file. The file lives on the host (its path comes from the compose labels), so we read it directly for the local daemon or over SSH for ssh hosts. TCP hosts give us no filesystem access. Returns the resolved path and contents.

func (*Manager) StreamEvents

func (m *Manager) StreamEvents(ctx context.Context, hostID int64, onEvent func(EventMsg)) error

StreamEvents forwards live daemon events to onEvent until the context is cancelled or the daemon stream errors. It mirrors the pull/exec streaming pattern so the handler can bridge it straight to a WebSocket.

func (*Manager) StreamLogs

func (m *Manager) StreamLogs(ctx context.Context, hostID int64, id string, follow bool, tail string, emit func(LogLine)) error

StreamLogs tails a container's logs, invoking emit per line. When follow is true it streams until ctx is cancelled; tail bounds the initial backlog.

func (*Manager) StreamStats

func (m *Manager) StreamStats(ctx context.Context, hostID int64, id string, emit func(StatsSample)) error

StreamStats subscribes to a container's stats stream and invokes emit for each computed sample until ctx is cancelled or the stream ends.

func (*Manager) SystemInfo

func (m *Manager) SystemInfo(ctx context.Context, hostID int64) (*SystemInfo, error)

SystemInfo returns a summary of the Docker host.

func (*Manager) TagImage

func (m *Manager) TagImage(ctx context.Context, hostID int64, source, target string) error

TagImage adds a new tag (target) to an existing image (source). It is the prerequisite for pushing a local image under a registry-qualified name.

func (*Manager) Topology

func (m *Manager) Topology(ctx context.Context, hostID int64) (*Topology, error)

Topology builds the container↔network connectivity graph for a host.

func (*Manager) UpdateContainer

func (m *Manager) UpdateContainer(ctx context.Context, hostID int64, id string, memory, nanoCPUs int64, restartPolicy string) error

UpdateContainer adjusts a running container's resource limits and restart policy at runtime. Zero values leave the corresponding limit unchanged-as-set.

func (*Manager) UploadExtract added in v1.3.0

func (m *Manager) UploadExtract(ctx context.Context, hostID int64, id, destDir, filename string, body io.Reader) error

UploadExtract streams an archive into destDir, extracting it. The Docker CopyToContainer API takes a TAR and untars it (jailing traversal), so we convert the upload to a TAR stream based on its extension.

func (*Manager) VolumeCopyFrom added in v1.3.0

func (m *Manager) VolumeCopyFrom(ctx context.Context, hostID int64, volume, p string) (io.ReadCloser, container.PathStat, error)

VolumeCopyFrom streams a path out of a volume as a TAR archive.

func (*Manager) VolumeCopyTo added in v1.3.0

func (m *Manager) VolumeCopyTo(ctx context.Context, hostID int64, volume, destDir string, content io.Reader) error

VolumeCopyTo writes a TAR archive into a volume directory.

func (*Manager) VolumeDeletePath added in v1.3.0

func (m *Manager) VolumeDeletePath(ctx context.Context, hostID int64, volume, p string) error

VolumeDeletePath removes a path inside a volume.

func (*Manager) VolumeListPath added in v1.3.0

func (m *Manager) VolumeListPath(ctx context.Context, hostID int64, volume, p string) ([]FileEntry, error)

VolumeListPath lists one directory level inside a volume.

func (*Manager) VolumeMakeDir added in v1.3.0

func (m *Manager) VolumeMakeDir(ctx context.Context, hostID int64, volume, p string) error

VolumeMakeDir creates a directory inside a volume.

func (*Manager) VolumeUploadExtract added in v1.3.0

func (m *Manager) VolumeUploadExtract(ctx context.Context, hostID int64, volume, destDir, filename string, body io.Reader) error

VolumeUploadExtract extracts an archive into a volume directory.

func (*Manager) WatchEvents

func (m *Manager) WatchEvents(ctx context.Context, hostID int64, fn func(Event)) error

WatchEvents streams container events from the host, invoking fn for each, until ctx is cancelled or the stream errors.

type MountInfo

type MountInfo struct {
	Type        string `json:"type"`
	Source      string `json:"source"`
	Destination string `json:"destination"`
	RW          bool   `json:"rw"`
}

MountInfo describes a volume or bind mount.

type NetworkAttach

type NetworkAttach struct {
	Name       string `json:"name"`
	NetworkID  string `json:"networkId"`
	IPAddress  string `json:"ipAddress"`
	Gateway    string `json:"gateway"`
	MacAddress string `json:"macAddress"`
}

NetworkAttach links a container to a network with its assigned address.

type NetworkCreateRequest added in v1.3.0

type NetworkCreateRequest struct {
	Name       string            `json:"name"`
	Driver     string            `json:"driver"`
	Subnet     string            `json:"subnet"`
	Gateway    string            `json:"gateway"`
	Internal   bool              `json:"internal"`
	Attachable bool              `json:"attachable"`
	Labels     map[string]string `json:"labels"`
}

NetworkCreateRequest holds the user-supplied options for a new network.

type NetworkSummary

type NetworkSummary struct {
	ID         string   `json:"id"`
	Name       string   `json:"name"`
	Driver     string   `json:"driver"`
	Scope      string   `json:"scope"`
	Internal   bool     `json:"internal"`
	Subnets    []string `json:"subnets"`
	Containers []string `json:"containers"` // container IDs attached
}

NetworkSummary describes a Docker network for the networks/topology views.

type PortMapping

type PortMapping struct {
	IP          string `json:"ip,omitempty"`
	PrivatePort uint16 `json:"privatePort"`
	PublicPort  uint16 `json:"publicPort,omitempty"`
	Type        string `json:"type"`
}

PortMapping describes one published port.

type PortProbe added in v1.1.0

type PortProbe struct {
	PrivatePort uint16 `json:"privatePort"`
	PublicPort  uint16 `json:"publicPort"`
	Type        string `json:"type"` // tcp | udp
	GuessByPort string `json:"guessByPort"`
	Open        bool   `json:"open"`
	Detected    string `json:"detected"`        // active fingerprint, "" if inconclusive
	Info        string `json:"info,omitempty"`  // banner / Server header / TLS subject
	TLS         bool   `json:"tls"`             // a TLS handshake succeeded
	Error       string `json:"error,omitempty"` // why the probe failed (closed/timeout)
}

PortProbe is the result of inspecting one published container port: the passive guess (from the well-known port number) plus the active fingerprint of whatever is actually listening.

type PortSpec

type PortSpec struct {
	HostPort      string `json:"hostPort"`      // empty = expose only, no host binding
	ContainerPort string `json:"containerPort"` // required
	Proto         string `json:"proto"`         // tcp (default) | udp
}

PortSpec is one published port in a create request.

type PullProgress

type PullProgress struct {
	Status  string `json:"status,omitempty"`
	ID      string `json:"id,omitempty"`
	Current int64  `json:"current,omitempty"`
	Total   int64  `json:"total,omitempty"`
	Error   string `json:"error,omitempty"`
	Done    bool   `json:"done,omitempty"`
}

PullProgress is one progress update from an image pull, forwarded to the UI.

type ResourceOverview added in v1.1.0

type ResourceOverview struct {
	CPUs       int             `json:"cpus"`
	MemTotal   int64           `json:"memTotal"`
	Containers []ResourceUsage `json:"containers"`
}

ResourceOverview is a snapshot of how the running containers divide up the host's CPU and memory — the data behind the dashboard's usage breakdown.

type ResourceUsage added in v1.1.0

type ResourceUsage struct {
	ID         string  `json:"id"`
	Name       string  `json:"name"`
	CPUPercent float64 `json:"cpuPercent"` // share of total host CPU (0..100)
	MemBytes   uint64  `json:"memBytes"`
	MemPercent float64 `json:"memPercent"` // share of total host memory (0..100)
}

ResourceUsage is one container's live share of the host's CPU and memory.

type Stack added in v1.2.0

type Stack struct {
	Project    string           `json:"project"`
	ConfigFile string           `json:"configFile,omitempty"` // host path, from the label
	WorkingDir string           `json:"workingDir,omitempty"`
	Containers []StackContainer `json:"containers"`
	Running    int              `json:"running"`
}

Stack is a group of containers sharing a Compose project label.

type StackContainer added in v1.2.0

type StackContainer struct {
	ID      string        `json:"id"`
	Name    string        `json:"name"`
	Service string        `json:"service"`
	State   string        `json:"state"`
	Status  string        `json:"status"`
	Image   string        `json:"image"`
	Ports   []PortMapping `json:"ports,omitempty"`
}

StackContainer is one container belonging to a Compose stack.

type StatsSample

type StatsSample struct {
	ContainerID string  `json:"containerId"`
	Timestamp   int64   `json:"timestamp"` // unix millis
	CPUPercent  float64 `json:"cpuPercent"`
	MemUsage    uint64  `json:"memUsage"`
	MemLimit    uint64  `json:"memLimit"`
	MemPercent  float64 `json:"memPercent"`
	NetRx       uint64  `json:"netRx"`
	NetTx       uint64  `json:"netTx"`
	BlkRead     uint64  `json:"blkRead"`
	BlkWrite    uint64  `json:"blkWrite"`
	PIDs        uint64  `json:"pids"`
}

StatsSample is one point in a container's real-time resource time series.

type SystemInfo

type SystemInfo struct {
	HostName        string `json:"hostName"`
	ServerVersion   string `json:"serverVersion"`
	OperatingSystem string `json:"operatingSystem"`
	OSType          string `json:"osType"`
	OSVersion       string `json:"osVersion"`
	KernelVersion   string `json:"kernelVersion"`
	Architecture    string `json:"architecture"`
	CPUs            int    `json:"cpus"`
	MemTotal        int64  `json:"memTotal"`

	StorageDriver string `json:"storageDriver"`
	LoggingDriver string `json:"loggingDriver"`
	CgroupDriver  string `json:"cgroupDriver"`
	CgroupVersion string `json:"cgroupVersion"`
	DockerRootDir string `json:"dockerRootDir"`
	LiveRestore   bool   `json:"liveRestore"`

	Containers        int `json:"containers"`
	ContainersRunning int `json:"containersRunning"`
	ContainersPaused  int `json:"containersPaused"`
	ContainersStopped int `json:"containersStopped"`
	Images            int `json:"images"`
}

SystemInfo summarises the Docker host itself: hardware, OS/kernel and the engine configuration. Note that for Docker Desktop (Windows/macOS) these describe the engine's Linux VM, not the desktop OS — the Docker API does not expose the underlying host, so KernelVersion/OSType are the best hint (e.g. a "…microsoft-standard-WSL2" kernel reveals a Windows/WSL2 host).

type TopResult

type TopResult struct {
	Titles    []string   `json:"titles"`
	Processes [][]string `json:"processes"`
}

TopResult is the process listing inside a container (docker top).

type TopoContainer

type TopoContainer struct {
	ID    string        `json:"id"`
	Name  string        `json:"name"`
	Image string        `json:"image"`
	State string        `json:"state"`
	Stack string        `json:"stack,omitempty"` // compose project, for grouping/filtering
	Ports []PortMapping `json:"ports,omitempty"` // published ports, for the list views
}

TopoContainer is a container node in the topology graph.

type TopoLink struct {
	ContainerID string `json:"containerId"`
	NetworkID   string `json:"networkId"`
	IPAddress   string `json:"ipAddress"`
}

TopoLink is an edge: a container attached to a network with an assigned IP.

type TopoNetwork

type TopoNetwork struct {
	ID       string   `json:"id"`
	Name     string   `json:"name"`
	Driver   string   `json:"driver"`
	Scope    string   `json:"scope"`
	Internal bool     `json:"internal"`
	Subnets  []string `json:"subnets"`
}

TopoNetwork is a network node in the topology graph.

type Topology

type Topology struct {
	Networks   []TopoNetwork   `json:"networks"`
	Containers []TopoContainer `json:"containers"`
	Links      []TopoLink      `json:"links"`
}

Topology is a graph view of how containers attach to networks, consumed by the frontend connectivity diagram.

type UsageCategory

type UsageCategory struct {
	Count int   `json:"count"`
	Size  int64 `json:"size"`
}

UsageCategory is a count + total size for one class of Docker object.

type VolumePruneResult

type VolumePruneResult struct {
	Deleted        []string `json:"deleted"`
	SpaceReclaimed uint64   `json:"spaceReclaimed"`
}

VolumePruneResult reports what an unused-volume prune removed.

type VolumeSummary

type VolumeSummary struct {
	Name       string            `json:"name"`
	Driver     string            `json:"driver"`
	Mountpoint string            `json:"mountpoint"`
	Scope      string            `json:"scope"`
	CreatedAt  string            `json:"createdAt"`
	Labels     map[string]string `json:"labels"`
	InUseBy    []string          `json:"inUseBy"` // container names mounting this volume
}

VolumeSummary describes a Docker volume for the Volumes page, including which containers currently mount it so removal is informed.

Jump to

Keyboard shortcuts

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