docker

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package docker reads the state of stacks from the Docker Engine API. Docker is siding's database: containers, networks and volumes with their labels are all it knows.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MemoryUsage

func MemoryUsage(usage uint64, stats map[string]uint64) uint64

MemoryUsage subtracts the inactive page cache from usage: inactive_file on cgroup v2, total_inactive_file on cgroup v1.

Types

type Client

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

Client talks to the Docker daemon that docker and docker compose use.

func (*Client) Container

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

Container returns the container with this name, or nil when there is none.

func (*Client) Containers

func (c *Client) Containers(ctx context.Context, labels map[string]string) ([]Container, error)

Containers returns every container, running or not, that carries all the given labels; an empty value matches any value.

func (*Client) CreateVolume

func (c *Client) CreateVolume(ctx context.Context, name string, labels map[string]string) error

CreateVolume creates a new volume with labels. It fails when the name is taken: Docker would silently hand back the existing volume, and siding would write into someone else's data.

func (*Client) EnsureNetwork

func (c *Client) EnsureNetwork(ctx context.Context, name string, labels map[string]string) (bool, error)

EnsureNetwork creates the network unless it exists and reports whether it created it.

func (*Client) Logs

func (c *Client) Logs(ctx context.Context, id string, tail int) ([]string, error)

Logs returns the last tail lines a container wrote to stdout and stderr, in order.

func (*Client) MemTotal

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

MemTotal returns the memory the Docker daemon has, the VM's on Docker Desktop.

func (*Client) Memory

func (c *Client) Memory(ctx context.Context, id string) (uint64, error)

Memory returns the memory a running container uses now, counted as docker stats counts it (usage without the inactive page cache).

func (*Client) NCPU

func (c *Client) NCPU(ctx context.Context) (int, error)

NCPU returns the CPUs the Docker daemon has, the VM's on Docker Desktop.

func (*Client) NetworkGateway

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

NetworkGateway returns the IPv4 gateway of a network, "" when it has none.

func (*Client) NetworkUsers

func (c *Client) NetworkUsers(ctx context.Context, name string) (exists bool, users []string, err error)

NetworkUsers returns the names of the containers attached to a network, and false when the network does not exist.

func (*Client) Networks

func (c *Client) Networks(ctx context.Context, labels map[string]string) ([]Network, error)

Networks returns the networks that carry all the given labels.

func (*Client) Ping

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

Ping fails with DockerUnavailable when the daemon cannot be reached.

func (*Client) RemoveNetwork

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

RemoveNetwork removes a network by its exact name.

func (*Client) RemoveVolume

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

RemoveVolume removes a volume by its exact name.

func (*Client) RunHelper

func (c *Client) RunHelper(ctx context.Context, h Helper) (exit int, output []string, err error)

RunHelper runs a helper container to its end, pulling its image first when it is missing, and removes it. It returns the exit code and the last lines of its output.

func (*Client) Stdout

func (c *Client) Stdout(ctx context.Context, id string) ([]string, error)

Stdout returns every line a container wrote to stdout that Docker still keeps, in order.

func (*Client) VolumeSizes

func (c *Client) VolumeSizes(ctx context.Context) (map[string]int64, error)

VolumeSizes returns the size of every volume by name, as docker system df -v reports it.

func (*Client) Volumes

func (c *Client) Volumes(ctx context.Context, labels map[string]string) ([]Volume, error)

Volumes returns the volumes that carry all the given labels.

type Container

type Container struct {
	ID     string
	Name   string
	Image  string
	Labels map[string]string
	// State is one of created, running, paused, restarting, removing, exited or dead.
	State string
	// Health is "", starting, healthy or unhealthy.
	Health string
	// HealthOutput is the output of the last healthcheck.
	HealthOutput string
	ExitCode     int
	RestartCount int
	OOMKilled    bool
	Ports        []Port
	// StartedAt is when the container last started; zero when it never did.
	StartedAt time.Time
	// Cmd is the container's command, its arguments after the image's entrypoint.
	Cmd []string
}

Container is what siding knows about one container.

type Helper

type Helper struct {
	Image string
	// Binds are volume mounts, "<volume>:<path>[:ro]".
	Binds  []string
	Cmd    []string
	Labels map[string]string
}

Helper is a short-lived container that works on volumes, such as copying one into another.

type Network

type Network struct {
	Name   string
	Labels map[string]string
}

Network is a Docker network.

type Port

type Port struct {
	HostIP        string
	HostPort      int
	ContainerPort int
}

Port is a published port.

type Volume

type Volume struct {
	Name    string
	Labels  map[string]string
	Created string
	// Size in bytes, set only by VolumeSizes; -1 when Docker does not know it.
	Size int64
}

Volume is a Docker volume.

Jump to

Keyboard shortcuts

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