docker

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ManagedLabel marks containers created by ci-debugger for cleanup.
	ManagedLabel = "ci-debugger=true"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client wraps the Docker SDK client.

func NewClient

func NewClient() (*Client, error)

NewClient creates a new Docker client using environment configuration.

func (*Client) Close

func (c *Client) Close() error

Close closes the Docker client.

func (*Client) CopyDirToContainer

func (c *Client) CopyDirToContainer(ctx context.Context, containerID, localDir, destDir string) error

CopyDirToContainer copies the contents of localDir into destDir inside the container. destDir must already exist in the container (e.g. /tmp/). Each file is placed at destDir/<relpath> where relpath is relative to localDir.

func (*Client) CreateContainer

func (c *Client) CreateContainer(ctx context.Context, opts ContainerOpts) (string, error)

CreateContainer creates and returns a container ID. The container uses "tail -f /dev/null" as entrypoint to stay alive.

func (*Client) CreateNetwork

func (c *Client) CreateNetwork(ctx context.Context, name string) (string, error)

CreateNetwork creates a bridge network and returns its ID.

func (*Client) CreateServiceContainer

func (c *Client) CreateServiceContainer(ctx context.Context, opts ContainerOpts) (string, error)

CreateServiceContainer creates a service sidecar container using the image's own CMD/ENTRYPOINT (not overridden), and registers the service name as a network alias so job steps can reach it by hostname.

func (*Client) ExecInContainer

func (c *Client) ExecInContainer(ctx context.Context, containerID string, opts ExecOpts) (*ExecResult, error)

ExecInContainer runs a command in a running container and captures output.

func (*Client) ExecStreaming

func (c *Client) ExecStreaming(ctx context.Context, containerID string, opts ExecOpts, outWriter, errWriter io.Writer) (int, error)

ExecStreaming runs a command and streams output line-by-line via callbacks.

func (*Client) ImageExists

func (c *Client) ImageExists(ctx context.Context, imageName string) (bool, error)

ImageExists checks if an image is available locally.

func (*Client) OpenInteractiveShell

func (c *Client) OpenInteractiveShell(ctx context.Context, containerID, workDir string) error

OpenInteractiveShell starts an interactive bash session in the container.

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) error

Ping verifies the Docker daemon is reachable.

func (*Client) PullImage

func (c *Client) PullImage(ctx context.Context, imageName string) error

PullImage pulls a Docker image, showing progress.

func (*Client) Raw

func (c *Client) Raw() *dockerclient.Client

Raw returns the underlying Docker client (for advanced operations).

func (*Client) RemoveNetwork

func (c *Client) RemoveNetwork(ctx context.Context, networkID string)

RemoveNetwork removes a Docker network by ID.

func (*Client) StartContainer

func (c *Client) StartContainer(ctx context.Context, containerID string) error

StartContainer starts a container by ID.

func (*Client) StopAndRemove

func (c *Client) StopAndRemove(ctx context.Context, containerID string) error

StopAndRemove stops and removes a container.

func (*Client) WaitContainer

func (c *Client) WaitContainer(ctx context.Context, containerID string) (int, error)

WaitContainer waits for a container to stop and returns its exit code.

func (*Client) WriteScript

func (c *Client) WriteScript(ctx context.Context, containerID, path, content string) error

WriteScript writes a shell script to a path inside the container via tar archive.

type ContainerOpts

type ContainerOpts struct {
	Image   string
	Name    string
	Env     []string // KEY=VALUE pairs
	Binds   []string // host:container[:options]
	WorkDir string
	Labels  map[string]string
	Network string // Docker network ID or name to attach to
}

ContainerOpts configures a new container.

type ExecOpts

type ExecOpts struct {
	Cmd     []string
	Env     []string // KEY=VALUE pairs
	WorkDir string
	TTY     bool
	Stdin   bool
}

ExecOpts configures an exec in a running container.

type ExecResult

type ExecResult struct {
	ExitCode int
	Stdout   string
	Stderr   string
}

ExecResult holds the output of a completed exec.

Jump to

Keyboard shortcuts

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