docker

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package docker provides Docker SDK client operations.

Package docker provides Docker SDK client operations.

Package docker provides Docker SDK client operations.

Package docker provides Docker SDK client operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StreamLogs

func StreamLogs(ctx context.Context, c DockerClient, containerID string, opts StreamLogsOpts) (<-chan LogLine, <-chan error)

StreamLogs streams logs from a container via a channel. It demultiplexes stdout/stderr using stdcopy for non-TTY containers.

func WatchEvents

func WatchEvents(ctx context.Context, c DockerClient, opts WatchEventsOpts) (<-chan ContainerEvent, <-chan error)

WatchEvents subscribes to Docker container events and streams them via a channel. It filters for start, stop, die, and restart events on containers matching the given criteria.

Types

type ContainerEvent

type ContainerEvent struct {
	Type          EventType
	ContainerID   string
	ContainerName string
	Time          time.Time
}

ContainerEvent represents a Docker container lifecycle event.

type ContainerInfo

type ContainerInfo struct {
	Name   string
	ID     string
	Image  string
	Labels map[string]string
}

ContainerInfo holds information about a discovered container.

func DiscoverContainers

func DiscoverContainers(ctx context.Context, c DockerClient, opts DiscoverOpts) ([]ContainerInfo, error)

DiscoverContainers lists running containers matching the given filters.

type DiscoverOpts

type DiscoverOpts struct {
	// GlobPattern filters container names (empty = all)
	GlobPattern string
	// ComposeProject filters by Docker Compose project label (empty = ignore)
	ComposeProject string
}

DiscoverOpts configures container discovery.

type DockerClient

type DockerClient interface {
	ContainerList(ctx context.Context, opts container.ListOptions) ([]container.Summary, error)
	ContainerLogs(ctx context.Context, containerID string, opts container.LogsOptions) (io.ReadCloser, error)
	ContainerInspect(ctx context.Context, containerID string) (types.ContainerJSON, error)
	Events(ctx context.Context, opts events.ListOptions) (<-chan events.Message, <-chan error)
	Close() error
}

DockerClient defines the interface for Docker SDK operations used by this tool. This allows for mocking in tests.

func NewClient

func NewClient(ctx context.Context) (DockerClient, error)

NewClient creates a Docker client with socket discovery. It tries sockets in this order: 1. $DOCKER_HOST environment variable 2. ~/.docker/run/docker.sock 3. /var/run/docker.sock

type EventType

type EventType string

EventType represents a Docker container event type.

const (
	EventStart   EventType = "start"
	EventStop    EventType = "stop"
	EventDie     EventType = "die"
	EventRestart EventType = "restart"
)

type LogLine

type LogLine struct {
	Timestamp     time.Time
	Stream        string // "stdout" or "stderr"
	Content       string
	ContainerName string
}

LogLine represents a single log entry from a container.

type StreamLogsOpts

type StreamLogsOpts struct {
	Follow        bool
	Since         time.Time
	ContainerName string
}

StreamLogsOpts configures log streaming.

type WatchEventsOpts

type WatchEventsOpts struct {
	// GlobPattern filters container names (empty = all)
	GlobPattern string
	// ComposeProject filters by Docker Compose project label (empty = ignore)
	ComposeProject string
}

WatchEventsOpts configures event watching.

Jump to

Keyboard shortcuts

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