Documentation
¶
Overview ¶
Package containers is the Docker plugin's container task layer, the one place the plugin turns what its providers want done into Docker Engine SDK calls: creating and removing networks, pulling images, creating, starting and removing containers, and moving containers between networks.
It speaks in its own data types, so the providers never import a Docker library. It is built on the narrow SDK interface in client/docker, the real SDK client when the plugin runs and a mock in this package's unit tests. Docker's "not found" errors come back matching ErrNotFound.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("docker object not found")
ErrNotFound is matched, with errors.Is, by the error a task returns when Docker reports that the network, container or image it names does not exist. The error keeps Docker's own message.
Functions ¶
This section is empty.
Types ¶
type Attachment ¶
type Attachment struct {
// Name is the Docker name of the network
Name string
// Aliases are extra names the container is known by on the network
Aliases []string
}
Attachment is a network a container joins, with the extra names it is known by there
type ContainerSpec ¶
type ContainerSpec struct {
// Name is the container's Docker name
Name string
// Image is the image the container runs
Image string
// Command overrides the image's command
Command []string
// Environment holds the container's environment variables, sent to
// Docker as KEY=VALUE sorted by key
Environment map[string]string
// Labels are put on the container
Labels map[string]string
// InitScript is the absolute host path of a script mounted read-only into
// the nginx image's entrypoint directory, "" for none
InitScript string
// Network is the network the container is created on, nil for none
Network *Attachment
}
ContainerSpec describes a container to create
type NetworkSpec ¶
type NetworkSpec struct {
// Subnet is the network's address range, Docker picks one when it is ""
Subnet string
// Labels are put on the network
Labels map[string]string
}
NetworkSpec describes a network to create
type Tasks ¶
type Tasks interface {
// CreateNetwork creates a labelled, attachable bridge network and
// returns its Docker ID
CreateNetwork(ctx context.Context, name string, spec NetworkSpec) (string, error)
// NetworkContainers returns the IDs of the containers attached to the
// network, sorted
NetworkContainers(ctx context.Context, networkID string) ([]string, error)
// RemoveNetwork removes the network
RemoveNetwork(ctx context.Context, networkID string) error
// ConnectNetwork attaches the container to the network with aliases
ConnectNetwork(ctx context.Context, network, containerID string, aliases []string) error
// DisconnectNetwork force-detaches the container from the network
DisconnectNetwork(ctx context.Context, network, containerID string) error
// EnsureImage pulls the image unless Docker already has it
EnsureImage(ctx context.Context, ref string) error
// CreateContainer creates the container and returns its Docker ID
CreateContainer(ctx context.Context, spec ContainerSpec) (string, error)
// StartContainer starts the container
StartContainer(ctx context.Context, containerID string) error
// StopContainer stops the container
StopContainer(ctx context.Context, containerID string) error
// RemoveContainer force-removes the container
RemoveContainer(ctx context.Context, containerID string) error
// ContainerAddresses returns the container's address on each network it
// is attached to, keyed by network name
ContainerAddresses(ctx context.Context, containerID string) (map[string]string, error)
}
Tasks are the Docker tasks the plugin's providers perform