docker

package
v2.3.1 Latest Latest
Warning

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

Go to latest
Published: May 25, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package docker contains helpers for working with Docker-compatible container runtimes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Check

func Check(ctx context.Context) error

Check attempts to connect to the local Docker daemon and returns an error if it's unable to do so.

func CopyFromContainer

func CopyFromContainer(ctx context.Context, cid, basePath string, fs afero.Fs) error

CopyFromContainer copies files from a container to an afero filesystem.

func GetContainerByName

func GetContainerByName(ctx context.Context, name string, includeStopped bool) (*container.Summary, bool, error)

GetContainerByName returns the container with the given name.

func GetContainerIDByName

func GetContainerIDByName(ctx context.Context, name string, includeStopped bool) (string, bool, error)

GetContainerIDByName returns the ID of the container with the given name.

func GetNetworkIDByName

func GetNetworkIDByName(ctx context.Context, name string) (string, bool, error)

GetNetworkIDByName returns the ID of the network with the given name.

func NewClient

func NewClient() (*client.Client, error)

NewClient creates a new Docker client configured from environment variables.

func RunContainer

func RunContainer(ctx context.Context, img string, opts ...RunContainerOption) ([]byte, []byte, error)

RunContainer creates a container, optionally pipes stdin, waits for it to exit, and returns stdout and stderr. The container is always removed on return. This is intended for short-lived "run to completion" containers.

func StartContainer

func StartContainer(ctx context.Context, name, img string, opts ...StartContainerOption) (string, error)

StartContainer starts a container with the given name using the given image.

func StartContainerByID

func StartContainerByID(ctx context.Context, id string) error

StartContainerByID starts an existing container by ID.

func StopContainerByID

func StopContainerByID(ctx context.Context, cid string) error

StopContainerByID stops and removes a container.

func TarFromContainer

func TarFromContainer(ctx context.Context, cid, path string) ([]byte, error)

TarFromContainer retrieves files from a container in a tarball (Docker's native file transfer format).

func WaitForContainerByID

func WaitForContainerByID(ctx context.Context, cid string) error

WaitForContainerByID waits for the container with the given ID to stop.

Types

type RunContainerOption

type RunContainerOption func(*runContainerConfig)

RunContainerOption provides optional options for RunContainer.

func RunWithBindMount

func RunWithBindMount(hostPath, containerPath string) RunContainerOption

RunWithBindMount adds a bind mount to the container.

func RunWithCommand

func RunWithCommand(cmd []string) RunContainerOption

RunWithCommand sets the command to run in the container.

func RunWithExtraHosts

func RunWithExtraHosts(hosts []string) RunContainerOption

RunWithExtraHosts adds extra /etc/hosts entries to the container (e.g. "host.docker.internal:host-gateway").

func RunWithNetworkName

func RunWithNetworkName(name string) RunContainerOption

RunWithNetworkName connects the container to a Docker network by name.

func RunWithStdin

func RunWithStdin(data []byte) RunContainerOption

RunWithStdin provides data to write to the container's stdin. The container is configured with OpenStdin and StdinOnce so it receives EOF after the data is written.

type StartContainerOption

type StartContainerOption func(*startContainerConfig)

StartContainerOption provides optional options for StartContainer.

func StartWithBindMount

func StartWithBindMount(hostPath, containerPath string) StartContainerOption

StartWithBindMount adds a bind mount when starting a container.

func StartWithCommand

func StartWithCommand(cmd []string) StartContainerOption

StartWithCommand sets the command to use when starting a container.

func StartWithCopyFiles

func StartWithCopyFiles(tarball []byte, path string) StartContainerOption

StartWithCopyFiles adds files that should be copied to the given path before starting the container.

func StartWithEnv

func StartWithEnv(env ...string) StartContainerOption

StartWithEnv adds environment variables that will be passed to the container.

func StartWithNetworkID

func StartWithNetworkID(nid string) StartContainerOption

StartWithNetworkID adds a network to which a container should be added.

func StartWithWorkingDirectory

func StartWithWorkingDirectory(path string) StartContainerOption

StartWithWorkingDirectory sets the working directory for the container.

Jump to

Keyboard shortcuts

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