docker

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package docker provides a thin client wrapper around the Docker Engine API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CollectContainerStats added in v0.2.0

func CollectContainerStats(client statsFetcher, ids []string, batchEvery time.Duration, deliver func(StatsBatch))

CollectContainerStats fetches stats for ids with bounded concurrency and delivers partial maps on batchEvery until all requests finish.

func StatsBatchInterval added in v0.2.0

func StatsBatchInterval() time.Duration

StatsBatchInterval is how often partial stats maps are delivered.

func StripDockerLogHeaderForUI

func StripDockerLogHeaderForUI(line string) string

Types

type Client

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

func NewClient

func NewClient() (*Client, error)

func (*Client) Close

func (c *Client) Close() error

func (*Client) GetAllContainerStats

func (c *Client) GetAllContainerStats(ids []string) map[string]*ContainerResourceStats

func (*Client) GetContainerDiff

func (c *Client) GetContainerDiff(id string) ([]DiffEntry, error)

func (*Client) GetContainerLogRecords

func (c *Client) GetContainerLogRecords(id string, lines int) ([]LogRecord, error)

func (*Client) GetContainerLogRecordsStream

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

func (*Client) GetContainerLogs

func (c *Client) GetContainerLogs(id string, lines int) (string, error)

func (*Client) GetContainerLogsStream

func (c *Client) GetContainerLogsStream(ctx context.Context, id string) (io.ReadCloser, error)

func (*Client) GetContainerStats

func (c *Client) GetContainerStats(id string) (*ContainerResourceStats, error)

func (*Client) GetContainerTop

func (c *Client) GetContainerTop(id string) (ContainerTop, error)

func (*Client) GetDockerOverview

func (c *Client) GetDockerOverview() (*DockerOverview, error)

func (*Client) InspectContainer

func (c *Client) InspectContainer(id string) (*ContainerInfo, error)

func (*Client) KillContainer

func (c *Client) KillContainer(id string, signal string) error

func (*Client) ListContainers

func (c *Client) ListContainers() ([]ContainerInfo, error)

func (*Client) ListImages

func (c *Client) ListImages() ([]ImageInfo, error)

func (*Client) ListNetworks

func (c *Client) ListNetworks() ([]NetworkResource, error)

func (*Client) ListVolumes

func (c *Client) ListVolumes() ([]VolumeInfo, error)

func (*Client) PauseContainer

func (c *Client) PauseContainer(id string) error

func (*Client) PruneDanglingImages

func (c *Client) PruneDanglingImages() (ImagePruneResult, error)

func (*Client) PruneVolumes

func (c *Client) PruneVolumes() ([]string, error)

func (*Client) PullImage

func (c *Client) PullImage(ref string) error

func (*Client) PullImageWithProgress

func (c *Client) PullImageWithProgress(ref string, onProgress func(string)) error

func (*Client) RemoveContainer

func (c *Client) RemoveContainer(id string, force bool) error

func (*Client) RemoveImage

func (c *Client) RemoveImage(id string, force bool) error

func (*Client) RemoveNetwork

func (c *Client) RemoveNetwork(id string) error

func (*Client) RemoveVolume

func (c *Client) RemoveVolume(name string) error

func (*Client) RestartContainer

func (c *Client) RestartContainer(id string) error

func (*Client) StartContainer

func (c *Client) StartContainer(id string) error

func (*Client) StartContainerExecShell

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

func (*Client) StopContainer

func (c *Client) StopContainer(id string) error

func (*Client) StreamEvents

func (c *Client) StreamEvents(ctx context.Context) <-chan DockerEvent

StreamEvents returns a channel of DockerEvents and a cancel func. Close the returned cancel to stop the stream.

func (*Client) SystemPrune

func (c *Client) SystemPrune() (SystemPruneResult, error)

func (*Client) UnpauseContainer

func (c *Client) UnpauseContainer(id string) error

type ClientAPI

type ClientAPI interface {
	// Container operations
	ListContainers() ([]ContainerInfo, error)
	InspectContainer(id string) (*ContainerInfo, error)
	StartContainer(id string) error
	StopContainer(id string) error
	RestartContainer(id string) error
	PauseContainer(id string) error
	UnpauseContainer(id string) error
	KillContainer(id string, signal string) error
	RemoveContainer(id string, force bool) error
	GetContainerDiff(id string) ([]DiffEntry, error)
	GetContainerTop(id string) (ContainerTop, error)
	GetContainerLogs(id string, lines int) (string, error)
	GetContainerLogRecords(id string, lines int) ([]LogRecord, error)
	GetContainerLogsStream(ctx context.Context, id string) (io.ReadCloser, error)
	GetContainerLogRecordsStream(ctx context.Context, id string, tail int) (io.ReadCloser, error)
	StartContainerExecShell(ctx context.Context, id, shell string) (io.ReadWriteCloser, error)

	// Stats
	GetContainerStats(id string) (*ContainerResourceStats, error)
	GetAllContainerStats(ids []string) map[string]*ContainerResourceStats

	// Images
	ListImages() ([]ImageInfo, error)
	RemoveImage(id string, force bool) error
	PullImage(ref string) error
	PullImageWithProgress(ref string, onProgress func(string)) error
	PruneDanglingImages() (ImagePruneResult, error)

	// Networks
	ListNetworks() ([]NetworkResource, error)
	RemoveNetwork(id string) error

	// Volumes
	ListVolumes() ([]VolumeInfo, error)
	RemoveVolume(name string) error
	PruneVolumes() ([]string, error)

	SystemPrune() (SystemPruneResult, error)

	// Events
	StreamEvents(ctx context.Context) <-chan DockerEvent

	// System info
	GetDockerOverview() (*DockerOverview, error)

	// Lifecycle
	Close() error
}

ClientAPI defines the Docker operations used by the UI. A concrete *Client satisfies this interface; tests can use a mock.

type ContainerInfo

type ContainerInfo struct {
	ID            string
	Name          string
	Image         string
	Status        string
	State         string
	Health        string
	Created       time.Time
	Ports         []PortBinding
	Mounts        []MountInfo
	Network       map[string]NetworkInfo
	Env           []string
	Labels        map[string]string
	Command       string
	Platform      string
	RestartCount  int
	StartedAt     time.Time
	CPUQuota      int64
	CPUPeriod     int64
	MemoryLimit   int64
	RestartPolicy string
}

type ContainerResourceStats

type ContainerResourceStats struct {
	CPUPercent float64
	MemUsage   uint64
	MemLimit   uint64
	MemPercent float64
	NetRx      uint64
	NetTx      uint64
	BlockRead  uint64
	BlockWrite uint64
	PIDs       uint64
}

type ContainerTop

type ContainerTop struct {
	Titles    []string
	Processes [][]string
}

type DiffEntry

type DiffEntry struct {
	Path string
	Kind string // "M" modify, "A" add, "D" delete
}

type DockerEvent

type DockerEvent struct {
	Time   time.Time
	Type   string
	Action string
	Actor  string
	ID     string
}

type DockerOverview

type DockerOverview struct {
	ServerVersion string
	Images        int
	TotalMemory   uint64
	CPUs          int
	OS            string
}

type FakeClient

type FakeClient struct {
	Containers []ContainerInfo
	Volumes    []VolumeInfo
	Networks   []NetworkResource
	Images     []ImageInfo
}

FakeClient is a minimal ClientAPI stub for tests.

func (*FakeClient) Close

func (f *FakeClient) Close() error

func (*FakeClient) GetAllContainerStats

func (f *FakeClient) GetAllContainerStats(ids []string) map[string]*ContainerResourceStats

func (*FakeClient) GetContainerDiff

func (f *FakeClient) GetContainerDiff(id string) ([]DiffEntry, error)

func (*FakeClient) GetContainerLogRecords

func (f *FakeClient) GetContainerLogRecords(id string, lines int) ([]LogRecord, error)

func (*FakeClient) GetContainerLogRecordsStream

func (f *FakeClient) GetContainerLogRecordsStream(ctx context.Context, id string, tail int) (io.ReadCloser, error)

func (*FakeClient) GetContainerLogs

func (f *FakeClient) GetContainerLogs(id string, lines int) (string, error)

func (*FakeClient) GetContainerLogsStream

func (f *FakeClient) GetContainerLogsStream(ctx context.Context, id string) (io.ReadCloser, error)

func (*FakeClient) GetContainerStats

func (f *FakeClient) GetContainerStats(id string) (*ContainerResourceStats, error)

func (*FakeClient) GetContainerTop

func (f *FakeClient) GetContainerTop(id string) (ContainerTop, error)

func (*FakeClient) GetDockerOverview

func (f *FakeClient) GetDockerOverview() (*DockerOverview, error)

func (*FakeClient) InspectContainer

func (f *FakeClient) InspectContainer(id string) (*ContainerInfo, error)

func (*FakeClient) KillContainer

func (f *FakeClient) KillContainer(id, signal string) error

func (*FakeClient) ListContainers

func (f *FakeClient) ListContainers() ([]ContainerInfo, error)

func (*FakeClient) ListImages

func (f *FakeClient) ListImages() ([]ImageInfo, error)

func (*FakeClient) ListNetworks

func (f *FakeClient) ListNetworks() ([]NetworkResource, error)

func (*FakeClient) ListVolumes

func (f *FakeClient) ListVolumes() ([]VolumeInfo, error)

func (*FakeClient) PauseContainer

func (f *FakeClient) PauseContainer(id string) error

func (*FakeClient) PruneDanglingImages

func (f *FakeClient) PruneDanglingImages() (ImagePruneResult, error)

func (*FakeClient) PruneVolumes

func (f *FakeClient) PruneVolumes() ([]string, error)

func (*FakeClient) PullImage

func (f *FakeClient) PullImage(ref string) error

func (*FakeClient) PullImageWithProgress

func (f *FakeClient) PullImageWithProgress(ref string, onProgress func(string)) error

func (*FakeClient) RemoveContainer

func (f *FakeClient) RemoveContainer(id string, force bool) error

func (*FakeClient) RemoveImage

func (f *FakeClient) RemoveImage(id string, force bool) error

func (*FakeClient) RemoveNetwork

func (f *FakeClient) RemoveNetwork(id string) error

func (*FakeClient) RemoveVolume

func (f *FakeClient) RemoveVolume(name string) error

func (*FakeClient) RestartContainer

func (f *FakeClient) RestartContainer(id string) error

func (*FakeClient) StartContainer

func (f *FakeClient) StartContainer(id string) error

func (*FakeClient) StartContainerExecShell

func (f *FakeClient) StartContainerExecShell(ctx context.Context, id, shell string) (io.ReadWriteCloser, error)

func (*FakeClient) StopContainer

func (f *FakeClient) StopContainer(id string) error

func (*FakeClient) StreamEvents

func (f *FakeClient) StreamEvents(ctx context.Context) <-chan DockerEvent

func (*FakeClient) SystemPrune

func (f *FakeClient) SystemPrune() (SystemPruneResult, error)

func (*FakeClient) UnpauseContainer

func (f *FakeClient) UnpauseContainer(id string) error

type ImageInfo

type ImageInfo struct {
	ID         string
	Tags       []string
	Size       int64
	Created    time.Time
	Containers int64
}

func (ImageInfo) DisplayTag

func (img ImageInfo) DisplayTag() string

type ImagePruneResult

type ImagePruneResult struct {
	DeletedRefs    []string
	SpaceReclaimed uint64
}

type LogRecord

type LogRecord struct {
	Timestamp time.Time
	Message   string
}

func DecodeDockerLogRecords

func DecodeDockerLogRecords(reader io.Reader) ([]LogRecord, error)

func ParseDockerLogRecord

func ParseDockerLogRecord(line string) LogRecord

type MountInfo

type MountInfo struct {
	Source      string
	Destination string
	Mode        string
	Type        string
	RW          bool
}

type NetworkInfo

type NetworkInfo struct {
	IPAddress  string
	Gateway    string
	MacAddress string
}

type NetworkResource

type NetworkResource struct {
	ID         string
	Name       string
	Driver     string
	Scope      string
	Internal   bool
	Attachable bool
	Labels     map[string]string
	Created    time.Time
}

type PortBinding

type PortBinding struct {
	HostIP   string
	HostPort string
	ContPort string
	Protocol string
}

type StatsBatch added in v0.2.0

type StatsBatch struct {
	Stats map[string]*ContainerResourceStats
	Done  bool
}

StatsBatch is one partial result from CollectContainerStats.

type SystemLoad

type SystemLoad struct {
	Load1  float64
	Load5  float64
	Load15 float64
}

SystemLoad holds host load averages.

func GetSystemLoad

func GetSystemLoad() SystemLoad

type SystemMemory

type SystemMemory struct {
	Total     uint64
	Used      uint64
	Available uint64
	Percent   float64
}

SystemMemory holds host memory statistics.

func GetSystemMemory

func GetSystemMemory() SystemMemory

type SystemPruneResult

type SystemPruneResult struct {
	ContainersDeleted int
	ImagesDeleted     int
	NetworksDeleted   int
	VolumesDeleted    int
	SpaceReclaimed    uint64
}

type VolumeInfo

type VolumeInfo struct {
	Name       string
	Driver     string
	Mountpoint string
	Labels     map[string]string
	Scope      string
	CreatedAt  time.Time
}

func (VolumeInfo) DisplayName

func (v VolumeInfo) DisplayName() string

Jump to

Keyboard shortcuts

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