docker

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2026 License: MIT Imports: 36 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrContainerFileLockHeld = errors.New("container file lock is already held")

Functions

func ExecCapture added in v0.13.4

func ExecCapture(ctx context.Context, cli *DockerClient, container, workingDir string, cmd []string) (string, error)

ExecCapture runs a command in a container and returns its stdout. stderr is used as the error detail when the command exits non-zero. workingDir may be empty to use the container's default.

func ExecCaptureWithInput added in v1.9.0

func ExecCaptureWithInput(ctx context.Context, cli *DockerClient, container, workingDir string, cmd []string, input io.Reader) (string, error)

ExecCaptureWithInput runs a command in a container with input attached and returns its stdout. The input is streamed directly to the command's stdin.

func GetConfigEnv

func GetConfigEnv(ctx context.Context, cli DockerAPI, containerName, envName string) (string, error)

func GetDatabaseUris added in v0.2.0

func GetDatabaseUris(c *config.Context) (string, string, error)

GetDatabaseUris constructs MySQL and SSH connection URIs for database tools like Sequel Ace Returns: mysqlURI, sshURI, error

func GetFirstSecretOrEnv added in v0.18.0

func GetFirstSecretOrEnv(ctx context.Context, cli DockerAPI, c *config.Context, containerName string, names ...string) (string, error)

GetFirstSecretOrEnv returns the first mounted secret or environment variable available from names on containerName.

func GetSecret

func GetSecret(ctx context.Context, cli DockerAPI, c *config.Context, containerName, secretName string) (string, error)

func IsExecutableNotFound added in v1.9.0

func IsExecutableNotFound(err error) bool

IsExecutableNotFound reports whether a container exec failed because its requested executable is not installed. Callers can use this to select a compatible binary without hiding operational failures from an installed one.

func TrimContainerName added in v0.13.3

func TrimContainerName(names []string) string

Types

type ContainerFileLock added in v1.2.0

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

ContainerFileLock holds an exclusive advisory lock through a connected container exec process. Release must be called when the protected operation finishes. A renewable lease releases an abandoned holder after 30 seconds.

func (*ContainerFileLock) Context added in v1.2.0

func (l *ContainerFileLock) Context() context.Context

Context is canceled if the parent context is canceled or the lock heartbeat is lost. Callers should use it for every operation protected by the lock.

func (*ContainerFileLock) Release added in v1.2.0

func (l *ContainerFileLock) Release() error

Release relinquishes the lock. It is safe to call more than once.

type ContainerFileLockOptions added in v1.2.0

type ContainerFileLockOptions struct {
	Container string
	Path      string
}

ContainerFileLockOptions identifies an advisory lock file inside a container.

type DockerAPI

type DockerAPI interface {
	ContainerInspect(ctx context.Context, container string) (dockercontainer.InspectResponse, error)
	ContainerList(ctx context.Context, options dockercontainer.ListOptions) ([]dockercontainer.Summary, error)
}

DockerAPI abstracts the Docker client functionality needed by our package.

type DockerClient

type DockerClient struct {
	CLI    DockerAPI
	SshCli *ssh.Client
	// contains filtered or unexported fields
}

func GetDockerCli

func GetDockerCli(activeCtx *config.Context) (*DockerClient, error)

func GetDockerCliWithSSH added in v0.12.0

func GetDockerCliWithSSH(activeCtx *config.Context, sshConn *ssh.Client, ownsSSH bool) (*DockerClient, error)

func (*DockerClient) AcquireContainerFileLock added in v1.2.0

func (d *DockerClient) AcquireContainerFileLock(ctx context.Context, options ContainerFileLockOptions) (*ContainerFileLock, error)

AcquireContainerFileLock takes a non-blocking exclusive flock inside the selected container. The lock path's parent directory must already exist. The container must provide flock and a shell whose read builtin supports -t.

func (*DockerClient) Close

func (d *DockerClient) Close() error

func (*DockerClient) Exec

func (d *DockerClient) Exec(ctx context.Context, opts ExecOptions) (int, error)

Exec executes a command in a container using the DockerClient

func (*DockerClient) ExecInteractive

func (d *DockerClient) ExecInteractive(ctx context.Context, containerID string, cmd []string) (int, error)

ExecInteractive executes an interactive command with TTY

func (*DockerClient) ExecSimple

func (d *DockerClient) ExecSimple(ctx context.Context, containerID string, cmd []string) (int, error)

ExecSimple executes a simple command and returns the exit code

func (*DockerClient) GetContainerName

func (d *DockerClient) GetContainerName(c *config.Context, service string) (string, error)

func (*DockerClient) GetContainerNameContext added in v0.12.0

func (d *DockerClient) GetContainerNameContext(ctx context.Context, c *config.Context, service string) (string, error)

func (*DockerClient) GetServiceIp

func (d *DockerClient) GetServiceIp(ctx context.Context, c *config.Context, containerName string) (string, error)

type ExecOptions

type ExecOptions struct {
	// Container is the container ID or name
	Container string

	// Cmd is the command to execute
	Cmd []string

	// Env is additional environment variables
	Env []string

	// WorkingDir is the working directory
	WorkingDir string

	// User to run as
	User string

	// AttachStdin attaches stdin
	AttachStdin bool

	// AttachStdout attaches stdout
	AttachStdout bool

	// AttachStderr attaches stderr
	AttachStderr bool

	// Tty allocates a pseudo-TTY
	Tty bool

	// Stdin is the input stream
	Stdin io.Reader

	// Stdout is the output stream
	Stdout io.Writer

	// Stderr is the error stream
	Stderr io.Writer
}

ExecOptions holds options for executing a command in a container

type ProjectSummary added in v0.10.0

type ProjectSummary struct {
	Running          int
	Total            int
	Healthy          int
	Stopped          int
	CPUPercent       float64
	MemoryBytes      uint64
	MemoryLimitBytes uint64
	HostLoad1        float64
	HostCPUCount     int
	DiskAvailable    uint64
	DiskTotal        uint64
	NetworkRXBytes   uint64
	NetworkTXBytes   uint64
	CollectedAt      time.Time
	Services         []ServiceSummary
	Status           string
}

func SummarizeProject added in v0.10.0

func SummarizeProject(ctxCfg *config.Context) (ProjectSummary, error)

func SummarizeProjectWithClient added in v0.10.0

func SummarizeProjectWithClient(ctx context.Context, cli DockerAPI, ctxCfg *config.Context) (ProjectSummary, error)

type ServiceSummary added in v0.10.0

type ServiceSummary struct {
	Service          string
	Name             string
	State            string
	Status           string
	Healthy          bool
	CPUPercent       float64
	MemoryBytes      uint64
	MemoryLimitBytes uint64
}

Jump to

Keyboard shortcuts

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