docker

package
v0.6.1 Latest Latest
Warning

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

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

Documentation

Overview

Package docker wraps the Docker Engine SDK behind a small interface the UI depends on, so the UI can be tested with a fake.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatPorts

func FormatPorts(ports []container.Port) string

FormatPorts renders ports compactly: "8080->80, 5432, 53/udp". The host IP is omitted when bound to all interfaces, IPv4/IPv6 duplicates collapse, and consecutive ports merge into ranges ("8081-8083->8081-8083").

Types

type Client

type Client interface {
	List(ctx context.Context, all bool) ([]tree.Container, error)
	// Events emits a value whenever a container changes. Bursts are
	// coalesced. The error channel reports a broken stream.
	Events(ctx context.Context) (<-chan struct{}, <-chan error)
	// Logs streams log lines until the stream ends or ctx is cancelled, then
	// closes the channel.
	Logs(ctx context.Context, id string, opts LogOptions) (<-chan LogLine, error)
	// Inspect returns the raw JSON of docker inspect.
	Inspect(ctx context.Context, id string) ([]byte, error)
	// Exec runs a command with sh -c in a terminal in the container and
	// streams its output. Docker cannot kill an exec'd process, so it is
	// stopped through its terminal with Interrupt; cancelling ctx only stops
	// the stream.
	Exec(ctx context.Context, id string, opts ExecOptions) (*ExecSession, error)
}

Client is everything the UI needs from Docker. Interactive shells are not part of it: the UI runs the docker CLI directly so it gets proper TTY handling.

type ExecOptions added in v0.3.0

type ExecOptions struct {
	Command       string
	Width, Height int
}

ExecOptions describes a command for Exec. Width and Height size its terminal.

type ExecResult added in v0.3.0

type ExecResult struct {
	ExitCode int
	Err      error // set when the command's outcome is unknown
}

ExecResult is how a command started with Exec ended.

type ExecSession added in v0.3.0

type ExecSession struct {
	// Output streams the raw terminal output, escape sequences included,
	// and closes when the command ends; then Result receives exactly one
	// value.
	Output <-chan []byte
	Result <-chan ExecResult
	// Input types p into the command's terminal. Calls must not overlap.
	Input func(p []byte) error
	// Interrupt types Ctrl+C into the command's terminal, which signals the
	// command and everything it started. With force it kills them instead,
	// for commands that ignore Ctrl+C.
	Interrupt func(force bool) error
}

ExecSession is a running Exec command.

type LogLine

type LogLine struct {
	Text   string
	Stderr bool
}

LogLine is one line of container output.

type LogOptions

type LogOptions struct {
	Tail       int
	Follow     bool
	Timestamps bool
}

type SDK

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

SDK is the Client backed by the Docker Engine API.

func New

func New(ctx context.Context) (*SDK, error)

New connects to the daemon selected by DOCKER_HOST or, failing that, the current docker CLI context (Docker Desktop, OrbStack, Colima, ...).

func (*SDK) Close

func (s *SDK) Close() error

func (*SDK) Events

func (s *SDK) Events(ctx context.Context) (<-chan struct{}, <-chan error)

func (*SDK) Exec added in v0.3.0

func (s *SDK) Exec(ctx context.Context, id string, opts ExecOptions) (*ExecSession, error)

func (*SDK) Inspect

func (s *SDK) Inspect(ctx context.Context, id string) ([]byte, error)

func (*SDK) List

func (s *SDK) List(ctx context.Context, all bool) ([]tree.Container, error)

func (*SDK) Logs

func (s *SDK) Logs(ctx context.Context, id string, opts LogOptions) (<-chan LogLine, error)

Jump to

Keyboard shortcuts

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