Documentation
¶
Overview ¶
Package docker provides a thin abstraction over the Docker CLI.
Index ¶
- Constants
- func SortedLabelFlags(labels Labels) []string
- type Client
- func (c *Client) AppendFile(ctx context.Context, container ContainerName, path, content string) error
- func (c *Client) ConnectNetwork(ctx context.Context, network NetworkName, container ContainerName) error
- func (c *Client) ContainerExists(ctx context.Context, name ContainerName) (bool, error)
- func (c *Client) CopyFilesToContainer(ctx context.Context, container ContainerName, destDir string, ...) error
- func (c *Client) CopyFromContainer(ctx context.Context, container ContainerName, srcPath string) ([]byte, error)
- func (c *Client) CopyToContainer(ctx context.Context, container ContainerName, destDir string, ...) error
- func (c *Client) CreateContainer(ctx context.Context, args ...string) (ContainerID, error)
- func (c *Client) CreateNetwork(ctx context.Context, name NetworkName, labels Labels) (NetworkID, error)
- func (c *Client) CreateVolume(ctx context.Context, name VolumeName, labels Labels) error
- func (c *Client) DisconnectNetwork(ctx context.Context, network NetworkName, container ContainerName) error
- func (c *Client) Exec(ctx context.Context, container ContainerName, command ...string) (string, error)
- func (c *Client) ExecWithStdin(ctx context.Context, container ContainerName, stdin io.Reader, ...) error
- func (c *Client) InspectContainer(ctx context.Context, name ContainerName) (*ContainerInfo, error)
- func (c *Client) InspectNetwork(ctx context.Context, name NetworkName) (*NetworkInfo, error)
- func (c *Client) KillContainer(ctx context.Context, name ContainerName) error
- func (c *Client) ListContainers(ctx context.Context, filters ...string) ([]ContainerListEntry, error)
- func (c *Client) ListNetworks(ctx context.Context, filters ...string) ([]NetworkListEntry, error)
- func (c *Client) ListVolumes(ctx context.Context, filters ...string) ([]VolumeListEntry, error)
- func (c *Client) NetworkExists(ctx context.Context, name NetworkName) (bool, error)
- func (c *Client) PauseContainer(ctx context.Context, name ContainerName) error
- func (c *Client) ReadFile(ctx context.Context, container ContainerName, path string) (string, error)
- func (c *Client) RemoveContainer(ctx context.Context, name ContainerName) error
- func (c *Client) RemoveNetwork(ctx context.Context, name NetworkName) error
- func (c *Client) RemoveVolume(ctx context.Context, name VolumeName) error
- func (c *Client) RunContainer(ctx context.Context, args ...string) (ContainerID, error)
- func (c *Client) RunEphemeral(ctx context.Context, image string, pull bool, command ...string) (string, error)
- func (c *Client) ServerVersion(ctx context.Context) (string, error)
- func (c *Client) SignalContainer(ctx context.Context, name ContainerName, signal string) error
- func (c *Client) StartContainer(ctx context.Context, name ContainerName) error
- func (c *Client) StopContainer(ctx context.Context, name ContainerName) error
- func (c *Client) UnpauseContainer(ctx context.Context, name ContainerName) error
- func (c *Client) VolumeExists(ctx context.Context, name VolumeName) (bool, error)
- func (c *Client) WriteFile(ctx context.Context, container ContainerName, path, content string) error
- type ContainerID
- type ContainerInfo
- type ContainerListEntry
- type ContainerName
- type ContainerState
- type File
- type FileContents
- type Labels
- type NetworkID
- type NetworkInfo
- type NetworkListEntry
- type NetworkName
- type VolumeListEntry
- type VolumeName
Constants ¶
const ( ComposeProjectLabel = "com.docker.compose.project" ComposeServiceLabel = "com.docker.compose.service" ComposeContainerNumberLabel = "com.docker.compose.container-number" ComposeOneoffLabel = "com.docker.compose.oneoff" ComposeConfigHashLabel = "com.docker.compose.config-hash" ComposeConfigFilesLabel = "com.docker.compose.project.config_files" ComposeNetworkLabel = "com.docker.compose.network" ComposeVolumeLabel = "com.docker.compose.volume" )
Docker Compose compatibility labels. See https://github.com/docker/compose/blob/main/pkg/api/labels.go
Variables ¶
This section is empty.
Functions ¶
func SortedLabelFlags ¶ added in v0.7.0
SortedLabelFlags returns --label k=v flag pairs in sorted key order. Returns nil when labels is nil or empty.
Types ¶
type Client ¶
type Client struct {
Executor cmdexec.Executor
Command string // docker executable path (default: "docker")
}
Client provides operations against the Docker CLI.
func (*Client) AppendFile ¶
func (c *Client) AppendFile(ctx context.Context, container ContainerName, path, content string) error
AppendFile appends content to a file in a running container via docker exec.
func (*Client) ConnectNetwork ¶
func (c *Client) ConnectNetwork(ctx context.Context, network NetworkName, container ContainerName) error
ConnectNetwork connects a container to a network.
func (*Client) ContainerExists ¶
ContainerExists returns true if the given container exists (running or stopped).
func (*Client) CopyFilesToContainer ¶
func (c *Client) CopyFilesToContainer(ctx context.Context, container ContainerName, destDir string, files map[string]File) error
CopyFilesToContainer writes files into a container directory via docker cp. Each file carries its own content and permissions. The container may be running or stopped. Keys are sorted for deterministic tar output.
func (*Client) CopyFromContainer ¶
func (c *Client) CopyFromContainer(ctx context.Context, container ContainerName, srcPath string) ([]byte, error)
CopyFromContainer reads a single file from a container via docker cp. The container may be running or stopped.
func (*Client) CopyToContainer ¶
func (c *Client) CopyToContainer(ctx context.Context, container ContainerName, destDir string, files FileContents) error
CopyToContainer writes files into a container directory via docker cp. All files are written with mode 0644. Use CopyFilesToContainer for explicit per-file permissions.
func (*Client) CreateContainer ¶
CreateContainer creates a container without starting it (docker create). Use StartContainer to start it afterwards. Returns the container ID.
func (*Client) CreateNetwork ¶
func (c *Client) CreateNetwork(ctx context.Context, name NetworkName, labels Labels) (NetworkID, error)
CreateNetwork creates a Docker network and returns its ID. Labels are applied as --label flags when non-nil.
func (*Client) CreateVolume ¶
CreateVolume creates a Docker volume. Labels are applied as --label flags when non-nil.
func (*Client) DisconnectNetwork ¶
func (c *Client) DisconnectNetwork(ctx context.Context, network NetworkName, container ContainerName) error
DisconnectNetwork disconnects a container from a network.
func (*Client) Exec ¶
func (c *Client) Exec(ctx context.Context, container ContainerName, command ...string) (string, error)
Exec runs a command inside a container and returns its stdout.
func (*Client) ExecWithStdin ¶
func (c *Client) ExecWithStdin(ctx context.Context, container ContainerName, stdin io.Reader, command ...string) error
ExecWithStdin runs a command inside a container, piping stdin to it.
func (*Client) InspectContainer ¶
func (c *Client) InspectContainer(ctx context.Context, name ContainerName) (*ContainerInfo, error)
InspectContainer returns detailed information about a container.
func (*Client) InspectNetwork ¶
func (c *Client) InspectNetwork(ctx context.Context, name NetworkName) (*NetworkInfo, error)
InspectNetwork returns detailed information about a network.
func (*Client) KillContainer ¶
func (c *Client) KillContainer(ctx context.Context, name ContainerName) error
KillContainer sends SIGKILL to a running container (docker kill).
func (*Client) ListContainers ¶
func (c *Client) ListContainers(ctx context.Context, filters ...string) ([]ContainerListEntry, error)
ListContainers returns containers matching the given filters. Each filter is passed as a --filter flag to docker ps (e.g. "label=sind.cluster").
func (*Client) ListNetworks ¶
ListNetworks returns networks matching the given filters. Each filter is passed as a --filter flag (e.g. "name=sind").
func (*Client) ListVolumes ¶
ListVolumes returns volumes matching the given filters. Each filter is passed as a --filter flag (e.g. "name=sind-dev").
func (*Client) NetworkExists ¶
NetworkExists returns true if the given network exists.
func (*Client) PauseContainer ¶
func (c *Client) PauseContainer(ctx context.Context, name ContainerName) error
PauseContainer suspends all processes in a container (docker pause).
func (*Client) ReadFile ¶
func (c *Client) ReadFile(ctx context.Context, container ContainerName, path string) (string, error)
ReadFile reads a file from a running container via docker exec.
func (*Client) RemoveContainer ¶
func (c *Client) RemoveContainer(ctx context.Context, name ContainerName) error
RemoveContainer force-removes a container. If the container is running it is killed first. This is equivalent to docker rm -f.
func (*Client) RemoveNetwork ¶
func (c *Client) RemoveNetwork(ctx context.Context, name NetworkName) error
RemoveNetwork removes a Docker network.
func (*Client) RemoveVolume ¶
func (c *Client) RemoveVolume(ctx context.Context, name VolumeName) error
RemoveVolume removes a Docker volume.
func (*Client) RunContainer ¶
RunContainer creates and starts a container in detached mode (docker run -d). The args are passed directly and should include the image name as the last element. Returns the container ID.
func (*Client) RunEphemeral ¶
func (c *Client) RunEphemeral(ctx context.Context, image string, pull bool, command ...string) (string, error)
RunEphemeral runs a command in a temporary container and returns its stdout. The container is removed after the command completes (docker run --rm). When pull is true, --pull always is added to force a fresh image pull.
func (*Client) ServerVersion ¶ added in v0.2.0
ServerVersion returns the Docker Engine server version string.
func (*Client) SignalContainer ¶
SignalContainer sends a signal to a running container (docker kill -s).
func (*Client) StartContainer ¶
func (c *Client) StartContainer(ctx context.Context, name ContainerName) error
StartContainer starts a stopped container.
func (*Client) StopContainer ¶
func (c *Client) StopContainer(ctx context.Context, name ContainerName) error
StopContainer gracefully stops a running container.
func (*Client) UnpauseContainer ¶
func (c *Client) UnpauseContainer(ctx context.Context, name ContainerName) error
UnpauseContainer resumes a paused container (docker unpause).
func (*Client) VolumeExists ¶
VolumeExists returns true if the given volume exists.
type ContainerID ¶
type ContainerID string
ContainerID is a Docker container identifier (64 hex characters).
type ContainerInfo ¶
type ContainerInfo struct {
ID ContainerID
Name ContainerName
Status ContainerState
Labels Labels
IPs map[NetworkName]string
}
ContainerInfo holds inspected container details.
type ContainerListEntry ¶
type ContainerListEntry struct {
ID ContainerID
Name ContainerName
State ContainerState
Image string
Labels Labels
}
ContainerListEntry holds summary information from docker ps.
type ContainerName ¶
type ContainerName string
ContainerName is a human-readable Docker container name.
type ContainerState ¶ added in v0.7.0
type ContainerState string
ContainerState represents the state of a Docker container.
const ( StateRunning ContainerState = "running" StatePaused ContainerState = "paused" StateExited ContainerState = "exited" StateDead ContainerState = "dead" StateCreated ContainerState = "created" )
Known container states returned by Docker.
type FileContents ¶ added in v0.7.0
FileContents maps file paths to their raw content for copying into containers.
type Labels ¶ added in v0.7.0
Labels is a set of key-value metadata pairs applied to Docker resources.
func ComposeLabels ¶ added in v0.7.0
ComposeLabels returns the standard Docker Compose compatibility labels for a container. These labels make sind containers appear as part of a compose project.
type NetworkInfo ¶
type NetworkInfo struct {
ID string
Name NetworkName
Driver string
Subnet string
Gateway string
}
NetworkInfo holds detailed information about a Docker network.
type NetworkListEntry ¶
type NetworkListEntry struct {
Name NetworkName
Driver string
}
NetworkListEntry holds summary information from docker network ls.
type VolumeListEntry ¶
type VolumeListEntry struct {
Name VolumeName
Driver string
}
VolumeListEntry holds summary information from docker volume ls.