Documentation
¶
Overview ¶
Package docker contains helpers for working with Docker-compatible container runtimes.
Index ¶
- func Check(ctx context.Context) error
- func CopyFromContainer(ctx context.Context, cid, basePath string, fs afero.Fs) error
- func GetContainerByName(ctx context.Context, name string, includeStopped bool) (*container.Summary, bool, error)
- func GetContainerIDByName(ctx context.Context, name string, includeStopped bool) (string, bool, error)
- func GetNetworkIDByName(ctx context.Context, name string) (string, bool, error)
- func NewClient() (*client.Client, error)
- func RunContainer(ctx context.Context, img string, opts ...RunContainerOption) ([]byte, []byte, error)
- func StartContainer(ctx context.Context, name, img string, opts ...StartContainerOption) (string, error)
- func StartContainerByID(ctx context.Context, id string) error
- func StopContainerByID(ctx context.Context, cid string) error
- func TarFromContainer(ctx context.Context, cid, path string) ([]byte, error)
- func WaitForContainerByID(ctx context.Context, cid string) error
- type RunContainerOption
- type StartContainerOption
- func StartWithBindMount(hostPath, containerPath string) StartContainerOption
- func StartWithCommand(cmd []string) StartContainerOption
- func StartWithCopyFiles(tarball []byte, path string) StartContainerOption
- func StartWithEnv(env ...string) StartContainerOption
- func StartWithNetworkID(nid string) StartContainerOption
- func StartWithWorkingDirectory(path string) StartContainerOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Check ¶
Check attempts to connect to the local Docker daemon and returns an error if it's unable to do so.
func CopyFromContainer ¶
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 ¶
GetNetworkIDByName returns the ID of the network with the given name.
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 ¶
StartContainerByID starts an existing container by ID.
func StopContainerByID ¶
StopContainerByID stops and removes a container.
func TarFromContainer ¶
TarFromContainer retrieves files from a container in a tarball (Docker's native file transfer format).
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.