docker

package
v0.0.0-...-62a8954 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsCloudIgnored

func IsCloudIgnored(labels map[string]string) bool

IsCloudIgnored reports whether a container opts out of DockTail Cloud with docktail.cloud.ignore=true. Such a container is never reported to the cloud as a service; it only affects cloud reporting, never the reconciler.

Types

type Client

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

Client wraps the Docker client with our business logic

func NewClient

func NewClient(defaultTags []string) (*Client, error)

NewClient creates a new Docker client

func (*Client) Close

func (c *Client) Close() error

Close closes the Docker client

func (*Client) ContainerLogsTail

func (c *Client) ContainerLogsTail(ctx context.Context, containerID string, n int) ([]string, int, error)

ContainerLogsTail returns the last n log lines of a container plus the total captured byte size, reading both stdout and stderr.

func (*Client) ContainerStats

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

ContainerStats reads a single (non-streaming) docker stats sample for a container via the one-shot stats endpoint. It is read-only and used only by the optional cloud module. PreCPUStats is intentionally ignored — it is zero for a one-shot read, so CPU percentages are computed by the caller across successive samples.

func (*Client) EngineID

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

EngineID returns the docker engine ID — the stable host fingerprint and the cloud's billable unit. Persisted by dockerd; survives reboots/reinstalls.

func (*Client) GetCloudContainers

func (c *Client) GetCloudContainers(ctx context.Context) ([]*apptypes.ContainerService, error)

GetCloudContainers lists docktail-managed containers for cloud reporting, INCLUDING stopped/exited ones — unlike GetEnabledContainers, which is running-only because the serve reconciler must never target a dead container. Reporting stopped containers lets the cloud render them as down rather than dropping them, and reserves "removed" for containers that truly leave Docker.

Running containers are parsed at full fidelity (multiple/indexed services and funnel included). A non-running container whose live parse fails — direct mode needs a running IP — falls back to a minimal entry keyed by the same primary service name it carries when running, so it stays in the catalog as a down service instead of being seen as removed. Limitation: a stopped container that declares multiple indexed services reports only its primary service until it is running again.

func (*Client) GetEnabledContainers

func (c *Client) GetEnabledContainers(ctx context.Context) ([]*apptypes.ContainerService, error)

GetEnabledContainers returns all running containers managed by DockTail. A container can be managed by a Tailscale service, a funnel, or both.

func (*Client) GetOtherContainers

func (c *Client) GetOtherContainers(ctx context.Context) ([]OtherContainer, error)

GetOtherContainers lists every container that is NOT reported as a docktail service — unmanaged (neither docktail.service.enable nor docktail.funnel.enable set) or labelled docktail.cloud.ignore=true — INCLUDING stopped ones, for the cloud's container-inventory view. It is read-only and builds each entry straight from the container-list summary — no per-container inspect — so it stays cheap even on a busy host. Used only by the cloud module (DOCKTAIL_CLOUD_KEY set); docktail-managed containers are reported separately by GetCloudContainers as services.

func (*Client) HostSpecs

func (c *Client) HostSpecs(ctx context.Context) HostSpec

HostSpecs reads static host capacity from `docker info` (best-effort; zero values on error). Read once at agent start — these do not change at runtime.

func (*Client) Hostname

func (c *Client) Hostname(ctx context.Context) string

Hostname returns the host's name as docker reports it (display-only).

func (*Client) InspectCloud

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

InspectCloud inspects a container and extracts the runtime fields the cloud catalog wants. It is read-only.

func (*Client) IsRunning

func (c *Client) IsRunning(ctx context.Context, containerID string) (running, ok bool)

IsRunning best-effort reads whether a container's main process is running via inspect. ok is false when the inspect fails.

func (*Client) RestartCount

func (c *Client) RestartCount(ctx context.Context, containerID string) int

RestartCount best-effort reads a container's live restart count via inspect.

func (*Client) RunningContainersMemory

func (c *Client) RunningContainersMemory(ctx context.Context) (int64, error)

RunningContainersMemory sums memory usage excluding all file cache (falling back to the working set) of every running container on this engine. Active page cache must also be excluded so nightly reads don't look like CT memory pressure. Inside a Proxmox LXC this is the closest reading of the CT's memory use the agent can get: its own /proc and cgroup are the node's and its own container's, but every container here is charged to the CT. It misses only the CT's non-container processes (dockerd, systemd, sshd). A container that exits between the list and its stats call is skipped; an error is returned only when the list fails or no container could be sampled.

func (*Client) ServerVersion

func (c *Client) ServerVersion(ctx context.Context) string

ServerVersion returns the docker server version string (best-effort).

func (*Client) WatchEvents

func (c *Client) WatchEvents(ctx context.Context) (<-chan events.Message, <-chan error)

WatchEvents streams Docker container events

type CloudInfo

type CloudInfo struct {
	Image          string
	ImageTag       string
	State          string // running/exited/restarting/paused/created
	Health         string // healthy/unhealthy/starting (empty if no healthcheck)
	RestartCount   int
	ComposeProject string
	ComposeService string
	Networks       []string
}

CloudInfo is the runtime enrichment the cloud catalog needs that the reconciler's ContainerService does not already carry.

type ContainerStatsSample

type ContainerStatsSample struct {
	CPUTotalUsage  uint64 // cumulative container CPU time (ns)
	CPUSystemUsage uint64 // cumulative host CPU time (ns)
	OnlineCPUs     uint64 // CPUs available, for percentage normalization
	MemUsageBytes  int64  // working set: usage minus inactive file cache
	MemLimitBytes  int64  // effective limit: container limit, else host total
	// contains filtered or unexported fields
}

ContainerStatsSample is a single one-shot resource reading for a container. CPU is reported as the raw cumulative counters docker exposes; a percentage is the delta between two samples, so the caller keeps the previous one. Memory is the cache-adjusted working set and its effective limit, both ready to use directly.

type HostSpec

type HostSpec struct {
	OS            string
	KernelVersion string
	Arch          string
	CPUCores      int
	MemTotalBytes int64
}

HostSpec is static host capacity read once from `docker info` (display-only).

type OtherContainer

type OtherContainer struct {
	ID             string // short container id — identity within the host
	IsAgent        bool   // this container is running the reporting DockTail agent
	LabelIgnored   bool   // labelled docktail.cloud.ignore=true (never a service, never monitored)
	Name           string
	Image          string
	ImageTag       string
	State          string // running/exited/restarting/paused/created
	Status         string // human status line, e.g. "Up 3 hours (healthy)"
	Health         string // healthy/unhealthy/starting (best-effort, parsed from Status)
	ComposeProject string
	ComposeService string
	Ports          []string
	CreatedAt      int64 // unix seconds the container was created
}

OtherContainer is a NON-docktail container as seen for cloud reporting: limited, read-only metadata only. It carries no exec/deploy surface and is never health-checked — the cloud renders it as plain inventory alongside the monitored services.

Jump to

Keyboard shortcuts

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