Documentation
¶
Overview ¶
Package docker talks to the Docker Engine API exposed by Colima's unix socket. The client is created lazily so the app starts even when the VM is down. The connection is cached once established and survives colima restarts as long as the socket path is stable; a profile or socket-path change needs an Oriel restart.
Index ¶
- Constants
- type Client
- func (c *Client) Close() error
- func (c *Client) ComposeUpFile(ctx context.Context, dir, file, name string, ownName bool) (<-chan string, <-chan error, error)
- func (c *Client) ConnectContainer(ctx context.Context, networkID, containerID string) error
- func (c *Client) ContainerExists(ctx context.Context, idOrName string) (bool, error)
- func (c *Client) CreateNetwork(ctx context.Context, name, driver string, internal bool) (string, error)
- func (c *Client) DisconnectContainer(ctx context.Context, networkID, containerID string, force bool) error
- func (c *Client) EngineInfo(ctx context.Context) EngineInfo
- func (c *Client) ImageExists(ctx context.Context, idOrRef string) (bool, error)
- func (c *Client) InspectContainer(ctx context.Context, id string) (ContainerDetail, error)
- func (c *Client) InspectNetwork(ctx context.Context, id string) (*NetworkDetail, error)
- func (c *Client) ListContainers(ctx context.Context) ([]Container, error)
- func (c *Client) ListImages(ctx context.Context) ([]Image, error)
- func (c *Client) ListNetworks(ctx context.Context) ([]Network, error)
- func (c *Client) ListStacks(ctx context.Context) ([]Stack, error)
- func (c *Client) ListVolumes(ctx context.Context) ([]Volume, error)
- func (c *Client) NetworkExists(ctx context.Context, idOrName string) (bool, error)
- func (c *Client) PruneImages(ctx context.Context) (int, int64, error)
- func (c *Client) PruneVolumes(ctx context.Context) (int, int64, error)
- func (c *Client) PruneableVolumes(ctx context.Context) ([]VolumePreview, error)
- func (c *Client) PullImage(ctx context.Context, ref string, emit func(map[string]any)) error
- func (c *Client) RemoveContainer(ctx context.Context, id string, force bool) error
- func (c *Client) RemoveImage(ctx context.Context, id string, force bool) error
- func (c *Client) RemoveNetwork(ctx context.Context, id string) error
- func (c *Client) RemoveVolume(ctx context.Context, name string, force bool) error
- func (c *Client) RestartContainer(ctx context.Context, id string) error
- func (c *Client) RunCompose(ctx context.Context, project, action string) ([]string, error)
- func (c *Client) SearchImages(ctx context.Context, term string, limit int) ([]SearchResult, error)
- func (c *Client) StackExists(ctx context.Context, name string) (bool, error)
- func (c *Client) StartContainer(ctx context.Context, id string) error
- func (c *Client) StopContainer(ctx context.Context, id string) error
- func (c *Client) StreamCompose(ctx context.Context, project, action string) (<-chan string, <-chan error, error)
- func (c *Client) StreamEvents(ctx context.Context) (<-chan Event, <-chan error, error)
- func (c *Client) StreamLogs(ctx context.Context, id string, tail int, follow bool, until string, ...) error
- func (c *Client) SystemPrune(ctx context.Context, opts PruneOptions, emit func(string)) (PruneResult, error)
- func (c *Client) SystemUsage(ctx context.Context) (SystemUsage, error)
- func (c *Client) TagImage(ctx context.Context, id, ref string) error
- func (c *Client) VolumeExists(ctx context.Context, name string) (bool, error)
- type Container
- type ContainerDetail
- type EngineInfo
- type Event
- type IPAMEntry
- type Image
- type MountInfo
- type NetInfo
- type Network
- type NetworkDetail
- type NetworkEndpoint
- type Port
- type PruneOptions
- type PruneResult
- type Sampler
- type SearchResult
- type Stack
- type Stat
- type SystemUsage
- type Volume
- type VolumePreview
Constants ¶
const ComposeProjectLabel = "com.docker.compose.project"
ComposeProjectLabel groups containers into compose stacks.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps the Docker SDK with lazy, socket-aware connection management.
func New ¶
func New() *Client
New returns an unconnected client. The connection is established on first use.
func (*Client) ComposeUpFile ¶
func (c *Client) ComposeUpFile(ctx context.Context, dir, file, name string, ownName bool) (<-chan string, <-chan error, error)
ComposeUpFile deploys a discovered compose project by file path, it has no containers yet, so it can't be found by label. --project-directory is set so an adjacent .env and relative paths resolve; -p is passed only when the file doesn't declare its own name, so the resulting labels match what we discovered.
func (*Client) ConnectContainer ¶ added in v0.8.0
ConnectContainer attaches a container to a network. DisconnectContainer detaches it (force detaches even a running container).
func (*Client) ContainerExists ¶
ContainerExists reports whether a container with the given id or name exists.
func (*Client) CreateNetwork ¶ added in v0.8.0
func (c *Client) CreateNetwork(ctx context.Context, name, driver string, internal bool) (string, error)
CreateNetwork creates a user-defined network. Driver defaults to bridge. Engine-level addressing (custom subnets, gateways) is intentionally left to the engine, this is the everyday "give me a network to attach containers to" path.
func (*Client) DisconnectContainer ¶ added in v0.8.0
func (*Client) EngineInfo ¶
func (c *Client) EngineInfo(ctx context.Context) EngineInfo
EngineInfo pings the daemon via `docker info`. A nil/zero result (Reachable false) means the engine is down or unreachable, never an error to the caller.
func (*Client) ImageExists ¶
func (*Client) InspectContainer ¶
func (*Client) InspectNetwork ¶ added in v0.8.0
func (*Client) ListContainers ¶
ListContainers returns all containers (running and stopped).
func (*Client) ListStacks ¶
ListStacks groups all containers by their compose project label.
func (*Client) NetworkExists ¶
func (*Client) PruneImages ¶
PruneImages removes dangling images and reports what was reclaimed.
func (*Client) PruneVolumes ¶
func (*Client) PruneableVolumes ¶
func (c *Client) PruneableVolumes(ctx context.Context) ([]VolumePreview, error)
PruneableVolumes lists volumes no container references, exactly what a prune would remove, with sizes from the disk-usage API (0 when a driver can't report it, so the prune still works, the total is just approximate).
func (*Client) PullImage ¶
PullImage pulls ref and invokes emit for each progress object in the stream.
func (*Client) RemoveContainer ¶
func (*Client) RemoveImage ¶
func (*Client) RemoveVolume ¶
func (*Client) RestartContainer ¶
func (*Client) RunCompose ¶ added in v0.5.1
RunCompose runs a compose action and blocks until it finishes, returning the collected output lines. It's the synchronous wrapper over StreamCompose for callers without a live stream (the tool registry → MCP); the UI uses the streaming form so it can show progress.
func (*Client) SearchImages ¶
SearchImages queries the registry (Docker Hub) through the daemon, so it uses the same network path as a pull and needs no extra HTTP client or CORS dance.
func (*Client) StackExists ¶ added in v0.5.1
StackExists reports whether a compose project is currently known (it has containers, so ListStacks sees it). A not-yet-deployed project isn't "known" here, that's the discovery/deploy path, not a stack action.
func (*Client) StartContainer ¶
func (*Client) StreamCompose ¶
func (c *Client) StreamCompose(ctx context.Context, project, action string) (<-chan string, <-chan error, error)
StreamCompose runs a compose action against a discovered stack, streaming output. The stack's config-files and working-dir labels are replayed so compose targets exactly the original project definition.
func (*Client) StreamEvents ¶
StreamEvents emits relevant docker events until ctx is cancelled. The error channel yields a terminal error (e.g. the daemon going away).
func (*Client) StreamLogs ¶
func (c *Client) StreamLogs(ctx context.Context, id string, tail int, follow bool, until string, emit func(stream, ts, line string)) error
StreamLogs reads a container's logs, invoking emit per line. With follow=true it tails live until ctx is cancelled; with follow=false it returns one historical batch and stops. `until` (RFC3339Nano) bounds the batch to lines before that moment, the cursor for lazy-loading older lines. Timestamps are always on so each line carries the cursor; the ts is split out of the displayed text.
func (*Client) SystemPrune ¶
func (c *Client) SystemPrune(ctx context.Context, opts PruneOptions, emit func(string)) (PruneResult, error)
SystemPrune runs the selected prune steps (stopped containers, unused networks, dangling images, build cache, unused volumes). Build cache prunes dangling layers by default; BuildCacheAll (All:true) also removes cache for existing images, the larger amount SystemUsage previews. emit (nil-safe) gets a line per step.
func (*Client) SystemUsage ¶
func (c *Client) SystemUsage(ctx context.Context) (SystemUsage, error)
type Container ¶
type Container struct {
ID string `json:"id"`
Name string `json:"name"`
Image string `json:"image"`
ImageID string `json:"imageId"` // digest, for matching a container to its image
State string `json:"state"`
Status string `json:"status"`
Created int64 `json:"created"`
Ports []Port `json:"ports"`
Project string `json:"project"`
}
Container is the frontend-facing DTO; SDK types are not leaked past this package so the API contract stays stable across SDK upgrades.
type ContainerDetail ¶
type ContainerDetail struct {
ID string `json:"id"`
Name string `json:"name"`
Image string `json:"image"`
ImageID string `json:"imageId"`
Created string `json:"created"`
State string `json:"state"`
Running bool `json:"running"`
StartedAt string `json:"startedAt"`
ExitCode int `json:"exitCode"`
Health string `json:"health"`
RestartPolicy string `json:"restartPolicy"`
Command string `json:"command"`
WorkingDir string `json:"workingDir"`
Env []string `json:"env"`
Labels map[string]string `json:"labels"`
Mounts []MountInfo `json:"mounts"`
Networks []NetInfo `json:"networks"`
}
ContainerDetail is the curated inspect payload the UI shows in a detail panel.
type EngineInfo ¶
type EngineInfo struct {
Reachable bool
Host string
NCPU int
MemTotal int64
Architecture string
ServerVersion string
Driver string
OS string
}
EngineInfo is a generic snapshot of the Docker daemon, used to report status when there's no colima VM to describe.
type Event ¶
type Event struct {
Type string `json:"type"`
Action string `json:"action"`
ID string `json:"id"`
Name string `json:"name"`
}
Event is a trimmed docker event used to trigger live UI refreshes.
type NetworkDetail ¶ added in v0.8.0
type NetworkDetail struct {
ID string `json:"id"`
Name string `json:"name"`
Driver string `json:"driver"`
Scope string `json:"scope"`
Internal bool `json:"internal"`
Created string `json:"created"`
IPAM []IPAMEntry `json:"ipam"`
Containers []NetworkEndpoint `json:"containers"`
Options map[string]string `json:"options,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
}
NetworkDetail is the curated inspect payload the UI's detail view shows: the addressing (IPAM subnet/gateway) and which containers are attached, plus the driver options and labels.
type NetworkEndpoint ¶ added in v0.8.0
type PruneOptions ¶
type PruneOptions struct {
Containers bool
Images bool
Networks bool
BuildCache bool
BuildCacheAll bool
Volumes bool
}
PruneOptions selects which categories a system prune removes. Each maps to one `docker … prune` step; nothing runs unless explicitly selected. BuildCacheAll extends the build-cache step from dangling-only to every unused entry.
type PruneResult ¶
type PruneResult struct {
Containers int `json:"containers"`
Images int `json:"images"`
Networks int `json:"networks"`
Volumes int `json:"volumes"`
Reclaimed int64 `json:"reclaimed"`
}
PruneResult reports what a system prune removed.
type Sampler ¶
type Sampler struct {
// contains filtered or unexported fields
}
Sampler computes container CPU% by diffing successive one-shot readings, avoiding a persistent stats stream per container. One Sampler backs the single shared /api/stats SSE channel.
func NewSampler ¶
type SearchResult ¶
type SearchResult struct {
Name string `json:"name"`
Description string `json:"description"`
Stars int `json:"stars"`
Official bool `json:"official"`
}
SearchResult is one Docker Hub search hit.
type Stack ¶
type Stack struct {
Name string `json:"name"`
Running int `json:"running"`
Total int `json:"total"`
ConfigFiles string `json:"configFiles"`
WorkingDir string `json:"workingDir"`
Containers []Container `json:"containers"`
}
Stack is a discovered compose project (grouped by the project label).
type Stat ¶
type Stat struct {
ID string `json:"id"`
CPU float64 `json:"cpu"` // percent of total host CPU
Mem int64 `json:"mem"`
MemLimit int64 `json:"memLimit"`
}
Stat is a per-container resource sample for the frontend.
type SystemUsage ¶
type SystemUsage struct {
StoppedContainers int `json:"stoppedContainers"`
ContainersSize int64 `json:"containersSize"`
DanglingImages int `json:"danglingImages"`
ImagesSize int64 `json:"imagesSize"`
BuildCacheSize int64 `json:"buildCacheSize"`
UnusedVolumes int `json:"unusedVolumes"`
VolumesSize int64 `json:"volumesSize"`
Reclaimable int64 `json:"reclaimable"` // excludes volumes (opt-in)
}
SystemUsage summarises what a `docker system prune` would reclaim. Counts and sizes mirror what the prune actually removes (stopped containers, dangling images, inactive build cache) plus unused volumes shown separately.
type VolumePreview ¶
type VolumePreview struct {
Name string `json:"name"`
Size int64 `json:"size"`
CreatedAt string `json:"createdAt"`
}
VolumePreview is one prune candidate: an unused volume and (best-effort) the space it would reclaim.