docker

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DrainStatsBody added in v0.4.0

func DrainStatsBody(r io.ReadCloser)

DrainStatsBody is a test helper closing unused readers.

Types

type Client

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

Client wraps the official Docker SDK client.

func NewClient

func NewClient() (*Client, error)

NewClient creates a Client connected to the local Docker daemon via DOCKER_HOST / Unix socket.

func (*Client) Close

func (c *Client) Close() error

Close releases the underlying Docker client.

func (*Client) ExecCapture added in v0.4.0

func (c *Client) ExecCapture(ctx context.Context, containerID string, cmd []string) (output string, exitCode int, err error)

ExecCapture runs cmd inside containerID and returns combined stdout/stderr plus the exit code.

func (*Client) FetchLogLines added in v0.2.0

func (c *Client) FetchLogLines(ctx context.Context, containerID string, tail int) ([]string, error)

FetchLogLines returns the last tail lines of stdout+stderr as a slice (oldest first).

func (*Client) FetchStatesByID added in v0.2.0

func (c *Client) FetchStatesByID(ctx context.Context, ids []string) (map[string]ContainerState, error)

FetchStatesByID returns observed states keyed by container ID. IDs not found in the current list are omitted; callers keep the last known state.

func (*Client) Inspect added in v0.4.0

func (c *Client) Inspect(ctx context.Context, containerID string) (*InspectInfo, error)

Inspect returns distilled inspect data, cached for 2s per container. Polling must not inspect every container — callers request on demand.

func (*Client) ListAll added in v0.2.0

func (c *Client) ListAll(ctx context.Context) ([]ContainerInfo, error)

ListAll returns every container on the daemon (running and stopped).

func (*Client) Logs

func (c *Client) Logs(ctx context.Context, containerID string, lines int) (string, error)

Logs returns the last n lines of stdout+stderr for containerID.

func (*Client) StartEventsCh added in v0.5.0

func (c *Client) StartEventsCh(ctx context.Context) (<-chan ContainerEvent, <-chan error)

StartEventsCh streams container lifecycle events until ctx is cancelled. Callers should keep Poll as a fallback when the events stream is unavailable.

func (*Client) StartLogStreamCh added in v0.2.0

func (c *Client) StartLogStreamCh(ctx context.Context, containerID string, tail int) <-chan LogLineMsg

StartLogStreamCh launches a goroutine that tails container logs with Follow enabled. The channel closes when ctx is cancelled, the stream ends, or an error occurs.

func (*Client) StartPollCh added in v0.2.0

func (c *Client) StartPollCh(ctx context.Context) <-chan PollMsg

StartPollCh launches a background goroutine that polls Docker every 500 ms and sends a PollMsg on the returned channel. The goroutine exits when ctx is cancelled and the channel is then closed.

func (*Client) Stats added in v0.4.0

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

Stats reads a one-shot sample and computes CPU% via the docker-CLI delta formula.

type ContainerEvent added in v0.5.0

type ContainerEvent struct {
	Time        time.Time
	Action      string
	ContainerID string
	Image       string
	Name        string
	Project     string
	Service     string
	ExitCode    string
	Signal      string
	OOMKilled   bool
	Health      string
	Attributes  map[string]string
}

ContainerEvent is a distilled docker events message for containers.

type ContainerInfo added in v0.2.0

type ContainerInfo struct {
	ID       string
	Names    []string
	Image    string
	Labels   map[string]string
	State    ContainerState
	ExitCode *int     // parsed from Status "Exited (N) ..."; nil while running
	Status   string   // raw human-readable Docker status string
	Ports    []string // formatted "8080:80/tcp" (published) or "80/tcp" (exposed only)
	Created  int64    // unix seconds, from container.Summary.Created
}

ContainerInfo holds discovered container metadata from a single list call.

type ContainerState

type ContainerState int

ContainerState represents the observed lifecycle state of a container.

const (
	StatePending   ContainerState = iota // waiting on a dependency; not yet started
	StateStarting                        // container exists, health check running
	StateHealthy                         // running and health check passing (or no healthcheck)
	StateUnhealthy                       // health check explicitly failing
	StateExited                          // stopped with non-zero exit code
)

The set of observable container lifecycle states, ordered from not-yet-started to terminal.

func (ContainerState) String

func (s ContainerState) String() string

type HealthInfo added in v0.4.0

type HealthInfo struct {
	Status        string // starting|healthy|unhealthy
	FailingStreak int
	Log           []ProbeResult
}

HealthInfo captures the runtime health state and probe history.

type HealthcheckSpec added in v0.4.0

type HealthcheckSpec struct {
	Test                           []string
	Interval, Timeout, StartPeriod time.Duration
	Retries                        int
}

HealthcheckSpec captures the configured healthcheck from docker inspect.

type InspectInfo added in v0.4.0

type InspectInfo struct {
	ID, RestartPolicy, Error string
	StartedAt, FinishedAt    time.Time
	RestartCount             int
	OOMKilled                bool
	Env                      []string
	Health                   *HealthInfo
	Healthcheck              *HealthcheckSpec
}

InspectInfo is the normalized subset of docker inspect used by the doctor package. It intentionally avoids exposing Docker SDK structs to callers.

type LogLineMsg added in v0.2.0

type LogLineMsg struct {
	Line string
	Err  error
}

LogLineMsg carries one line from a streaming log follow, or anaconda terminal error.

type PollMsg added in v0.2.0

type PollMsg struct {
	Containers []ContainerInfo
}

PollMsg is a Bubble Tea message emitted each poll cycle with full container metadata.

type ProbeResult added in v0.4.0

type ProbeResult struct {
	Start, End time.Time
	ExitCode   int
	Output     string
}

ProbeResult is one healthcheck probe result from docker inspect.

type StatsInfo added in v0.4.0

type StatsInfo struct {
	CPUPercent float64
	MemUsage   uint64
	MemLimit   uint64
	NetRx      uint64
	NetTx      uint64
	PIDs       uint64
}

StatsInfo is the distilled one-shot container stats sample.

Jump to

Keyboard shortcuts

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