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 ¶
- func FormatPorts(ports []container.Port) string
- type Client
- type ExecOptions
- type ExecResult
- type ExecSession
- type LogLine
- type LogOptions
- type SDK
- func (s *SDK) Close() error
- func (s *SDK) Events(ctx context.Context) (<-chan struct{}, <-chan error)
- func (s *SDK) Exec(ctx context.Context, id string, opts ExecOptions) (*ExecSession, error)
- func (s *SDK) Inspect(ctx context.Context, id string) ([]byte, error)
- func (s *SDK) List(ctx context.Context, all bool) ([]tree.Container, error)
- func (s *SDK) Logs(ctx context.Context, id string, opts LogOptions) (<-chan LogLine, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatPorts ¶
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
ExecOptions describes a command for Exec. Width and Height size its terminal.
type ExecResult ¶ added in v0.3.0
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 LogOptions ¶
type SDK ¶
type SDK struct {
// contains filtered or unexported fields
}
SDK is the Client backed by the Docker Engine API.
func New ¶
New connects to the daemon selected by DOCKER_HOST or, failing that, the current docker CLI context (Docker Desktop, OrbStack, Colima, ...).
func (*SDK) Exec ¶ added in v0.3.0
func (s *SDK) Exec(ctx context.Context, id string, opts ExecOptions) (*ExecSession, error)