docker

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package docker implements a Source that streams container logs from the Docker daemon and dynamically attaches to new containers matching a label or name selector.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	Ping(ctx context.Context) (interface{}, error) // returns types.Ping in practice; not used by our code
	ContainerList(ctx context.Context, opts container.ListOptions) ([]container.Summary, error)
	ContainerLogs(ctx context.Context, id string, opts container.LogsOptions) (io.ReadCloser, error)
	Events(ctx context.Context, opts events.ListOptions) (<-chan events.Message, <-chan error)
	Close() error
}

Client is the subset of the docker SDK we depend on. Defining it as an interface lets tests substitute a fake.

type Config

type Config struct {
	Name       string
	Container  string            // exact container name match
	Labels     map[string]string // optional label filter (AND semantics)
	MaxLineLen int
}

Config holds the docker source's runtime parameters.

type Source

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

Source streams logs from containers matching either Container (name) or Labels (label k=v filter).

func New

func New(cfg Config) (*Source, error)

New constructs a docker Source using a real docker client from the environment (DOCKER_HOST, /var/run/docker.sock).

func (*Source) Close

func (s *Source) Close() error

Close cancels all per-container goroutines and closes the docker client.

func (*Source) Name

func (s *Source) Name() string

Name returns the source name.

func (*Source) Start

func (s *Source) Start(ctx context.Context) error

Start checks the docker socket, lists currently-running matching containers, and subscribes to events for newly-started ones.

func (*Source) Subscribe

func (s *Source) Subscribe(name string, bufSize int) <-chan source.LogLine

Subscribe returns a line channel for a named subscriber.

func (*Source) Unsubscribe

func (s *Source) Unsubscribe(name string)

Unsubscribe removes a subscriber and closes its channel; used during daemon.Reload to drop rules that are no longer configured.

Jump to

Keyboard shortcuts

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