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 ¶
- func MemoryUsage(usage uint64, stats map[string]uint64) uint64
- type Client
- func (c *Client) Container(ctx context.Context, name string) (*Container, error)
- func (c *Client) Containers(ctx context.Context, labels map[string]string) ([]Container, error)
- func (c *Client) CreateVolume(ctx context.Context, name string, labels map[string]string) error
- func (c *Client) EnsureNetwork(ctx context.Context, name string, labels map[string]string) (bool, error)
- func (c *Client) Logs(ctx context.Context, id string, tail int) ([]string, error)
- func (c *Client) MemTotal(ctx context.Context) (int64, error)
- func (c *Client) Memory(ctx context.Context, id string) (uint64, error)
- func (c *Client) NCPU(ctx context.Context) (int, error)
- func (c *Client) NetworkGateway(ctx context.Context, name string) (string, error)
- func (c *Client) NetworkUsers(ctx context.Context, name string) (exists bool, users []string, err error)
- func (c *Client) Networks(ctx context.Context, labels map[string]string) ([]Network, error)
- func (c *Client) Ping(ctx context.Context) error
- func (c *Client) RemoveNetwork(ctx context.Context, name string) error
- func (c *Client) RemoveVolume(ctx context.Context, name string) error
- func (c *Client) RunHelper(ctx context.Context, h Helper) (exit int, output []string, err error)
- func (c *Client) Stdout(ctx context.Context, id string) ([]string, error)
- func (c *Client) VolumeSizes(ctx context.Context) (map[string]int64, error)
- func (c *Client) Volumes(ctx context.Context, labels map[string]string) ([]Volume, error)
- type Container
- type Helper
- type Network
- type Port
- type Volume
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 ¶
Container returns the container with this name, or nil when there is none.
func (*Client) Containers ¶
Containers returns every container, running or not, that carries all the given labels; an empty value matches any value.
func (*Client) CreateVolume ¶
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 ¶
Logs returns the last tail lines a container wrote to stdout and stderr, in order.
func (*Client) MemTotal ¶
MemTotal returns the memory the Docker daemon has, the VM's on Docker Desktop.
func (*Client) Memory ¶
Memory returns the memory a running container uses now, counted as docker stats counts it (usage without the inactive page cache).
func (*Client) NetworkGateway ¶
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) RemoveNetwork ¶
RemoveNetwork removes a network by its exact name.
func (*Client) RemoveVolume ¶
RemoveVolume removes a volume by its exact name.
func (*Client) RunHelper ¶
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 ¶
Stdout returns every line a container wrote to stdout that Docker still keeps, in order.
func (*Client) VolumeSizes ¶
VolumeSizes returns the size of every volume by name, as docker system df -v reports it.
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.