docker

package
v1.2.12 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client wraps the Docker SDK client with reconnection logic.

func NewClient

func NewClient(host string, logger *slog.Logger) (*Client, error)

NewClient creates a new Docker client wrapper. If host is empty, it uses the default Docker socket.

func (*Client) API

func (c *Client) API() client.APIClient

API returns the underlying Docker API client for direct SDK calls.

func (*Client) Close

func (c *Client) Close() error

Close closes the Docker client connection.

func (*Client) Connect

func (c *Client) Connect(ctx context.Context) error

Connect pings the Docker daemon to verify connectivity.

func (*Client) ConnectWithRetry

func (c *Client) ConnectWithRetry(ctx context.Context) error

ConnectWithRetry attempts to connect with exponential backoff.

func (*Client) DiscoverAll

func (c *Client) DiscoverAll(ctx context.Context) ([]*cmodel.Container, error)

DiscoverAll performs a full container list + inspect pass, returning all discovered containers.

func (*Client) DiscoverAllWithLabels

func (c *Client) DiscoverAllWithLabels(ctx context.Context) ([]*DiscoveryResult, error)

DiscoverAllWithLabels is like DiscoverAll but also returns raw Docker labels and security configuration for each container.

func (*Client) FetchLogSnippet

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

FetchLogSnippet retrieves the last 50 lines of logs for storing as a snippet on exit events.

func (*Client) FetchLogs

func (c *Client) FetchLogs(ctx context.Context, containerID string, lines int, timestamps bool) ([]string, error)

FetchLogs retrieves the last N lines of logs from a container.

func (*Client) GetHealthInfo

func (c *Client) GetHealthInfo(ctx context.Context, containerID string) (*HealthInfo, error)

GetHealthInfo inspects a container and returns its health check configuration and status.

func (*Client) Info added in v1.2.0

func (c *Client) Info(ctx context.Context) (system.Info, error)

Info returns the Docker system info (includes Swarm state).

func (*Client) IsConnected

func (c *Client) IsConnected() bool

IsConnected returns the current connection status.

func (*Client) Logger

func (c *Client) Logger() *slog.Logger

Logger returns the client logger for use in event processing.

func (*Client) NetworkInspect added in v1.2.0

func (c *Client) NetworkInspect(ctx context.Context, networkID string) (network.Inspect, error)

NetworkInspect returns details for a network by ID.

func (*Client) NodeList added in v1.2.0

func (c *Client) NodeList(ctx context.Context) ([]swarm.Node, error)

NodeList returns all Swarm nodes.

func (*Client) ServiceInspect added in v1.2.0

func (c *Client) ServiceInspect(ctx context.Context, serviceID string) (swarm.Service, error)

ServiceInspect returns a single Swarm service with raw data.

func (*Client) ServiceList added in v1.2.0

func (c *Client) ServiceList(ctx context.Context) ([]swarm.Service, error)

ServiceList returns all Swarm services.

func (*Client) SetDisconnected

func (c *Client) SetDisconnected()

SetDisconnected marks the client as disconnected.

func (*Client) StatsOneShot

func (c *Client) StatsOneShot(ctx context.Context, containerID string) (*ContainerStats, error)

StatsOneShot retrieves a single stats snapshot for a container. It uses the one-shot API which returns immediately without a priming read.

func (*Client) StreamEvents

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

StreamEvents subscribes to Docker container events and sends them to the returned channel. On disconnection, it reconnects with backoff and uses Since to avoid missing events. The caller should cancel ctx to stop the stream.

func (*Client) StreamLogs

func (c *Client) StreamLogs(ctx context.Context, dockerID string, lines int, timestamps bool) (io.ReadCloser, bool, error)

StreamLogs returns an io.ReadCloser that follows container logs in real-time. isTTY indicates whether the container uses a TTY (determines demux needs).

func (*Client) SwarmInspect added in v1.2.0

func (c *Client) SwarmInspect(ctx context.Context) (swarm.Swarm, error)

SwarmInspect returns the Swarm cluster metadata.

func (*Client) TaskList added in v1.2.0

func (c *Client) TaskList(ctx context.Context) ([]swarm.Task, error)

TaskList returns all Swarm tasks.

type ContainerEvent

type ContainerEvent struct {
	Action       string
	ExternalID   string
	Name         string
	ExitCode     string
	HealthStatus string
	ResourceType string // "container", "service", or "node"
	Timestamp    time.Time
	Labels       map[string]string
}

ContainerEvent represents a processed Docker container/service/node event.

type ContainerStats

type ContainerStats = dtypes.StatsResponse

ContainerStats holds the decoded stats response from Docker.

type DiscoveredContainer

type DiscoveredContainer struct {
	Container *cmodel.Container
	Err       error
}

DiscoveredContainer holds the result of discovering a single container.

type DiscoveryResult

type DiscoveryResult struct {
	Container      *cmodel.Container
	Labels         map[string]string
	SecurityConfig *SecurityConfig
}

DiscoveryResult holds a discovered container along with its raw labels for endpoint extraction.

type HealthInfo

type HealthInfo struct {
	HasHealthCheck bool
	Status         *cmodel.HealthStatus
}

HealthInfo holds parsed health check information from a container.

type PortBindingInfo added in v1.1.0

type PortBindingInfo struct {
	HostIP        string
	HostPort      string
	ContainerPort int
	Protocol      string
}

PortBindingInfo represents a single host port binding.

type Runtime

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

Runtime implements runtime.Runtime for Docker.

func NewRuntime

func NewRuntime(host string, logger *slog.Logger) (*Runtime, error)

NewRuntime creates a Docker runtime wrapping the Docker SDK client.

func (*Runtime) Client

func (r *Runtime) Client() *Client

Client returns the underlying Docker client for Docker-specific operations.

func (*Runtime) Close

func (r *Runtime) Close() error

func (*Runtime) Connect

func (r *Runtime) Connect(ctx context.Context) error

func (*Runtime) DiscoverAll

func (r *Runtime) DiscoverAll(ctx context.Context) ([]*cmodel.Container, error)

func (*Runtime) DiscoverAllWithLabels

func (r *Runtime) DiscoverAllWithLabels(ctx context.Context) ([]*DiscoveryResult, error)

DiscoverAllWithLabels delegates to the underlying Docker client for endpoint label discovery.

func (*Runtime) FetchLogSnippet

func (r *Runtime) FetchLogSnippet(ctx context.Context, externalID string) (string, error)

FetchLogSnippet retrieves the last 50 lines of logs for die event snippets. Satisfies container.LogFetcher interface.

func (*Runtime) FetchLogs

func (r *Runtime) FetchLogs(ctx context.Context, externalID string, lines int, timestamps bool) ([]string, error)

func (*Runtime) GetHealthInfo

func (r *Runtime) GetHealthInfo(ctx context.Context, externalID string) (*pbruntime.HealthInfo, error)

func (*Runtime) IsConnected

func (r *Runtime) IsConnected() bool

func (*Runtime) Logger

func (r *Runtime) Logger() *slog.Logger

Logger returns the runtime logger.

func (*Runtime) Name

func (r *Runtime) Name() string

func (*Runtime) SetDisconnected

func (r *Runtime) SetDisconnected()

func (*Runtime) StatsSnapshot

func (r *Runtime) StatsSnapshot(ctx context.Context, externalID string) (*pbruntime.RawStats, error)

func (*Runtime) StreamEvents

func (r *Runtime) StreamEvents(ctx context.Context) <-chan pbruntime.RuntimeEvent

func (*Runtime) StreamLogs

func (r *Runtime) StreamLogs(ctx context.Context, externalID string, lines int, timestamps bool) (io.ReadCloser, error)

type SecurityConfig added in v1.1.0

type SecurityConfig struct {
	Privileged   bool
	NetworkMode  string
	PortBindings []PortBindingInfo
}

SecurityConfig holds security-relevant fields extracted from Docker's ContainerInspect.

type SocketUnavailableError

type SocketUnavailableError struct {
	Err error
}

SocketUnavailableError is returned when the Docker socket is not accessible.

func (*SocketUnavailableError) Error

func (e *SocketUnavailableError) Error() string

func (*SocketUnavailableError) Unwrap

func (e *SocketUnavailableError) Unwrap() error

Jump to

Keyboard shortcuts

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