container

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package container provides Docker container lifecycle management for hawk's sandboxed execution environments. It wraps the Docker CLI to start, stop, inspect, and rebuild containers.

Index

Constants

View Source
const (
	CodeNotFound   = "not_found"
	CodeNotRunning = "not_running"
	CodeExecFailed = "exec_failed"
	CodeTimeout    = "timeout"
)

Error codes returned by ContainerError.

View Source
const (
	StateRunning  = "running"
	StateStopped  = "exited"
	StateNotFound = "not_found"
)

State constants returned by Status.

Variables

This section is empty.

Functions

func EnsureRunning

func EnsureRunning(ctx context.Context, containerID, image, workDir string) (string, error)

EnsureRunning guarantees that the specified container is in a running state. If the container is stopped, it starts it. If it does not exist, it creates a new one from the given image with the working directory mounted. Returns the container ID (which may differ from input if recreated).

func Rebuild

func Rebuild(ctx context.Context, containerID, newImage, workDir string) (string, error)

Rebuild stops and removes an existing container, then creates a new one from the specified image. The new container is started with sleep infinity and the given working directory mounted.

func Status

func Status(ctx context.Context, containerID string) (string, error)

Status queries Docker for the current state of a container. Returns StateRunning, StateStopped, or StateNotFound.

Types

type ContainerError

type ContainerError struct {
	Code    string
	Message string
}

ContainerError is a typed error with a machine-readable Code field.

func (*ContainerError) Error

func (e *ContainerError) Error() string

type ExecResult

type ExecResult struct {
	Stdout   string
	Stderr   string
	ExitCode int
}

ExecResult holds the output of a command executed in a container.

func ExecWithStdin

func ExecWithStdin(ctx context.Context, containerID string, cmd []string, stdin []byte) (*ExecResult, error)

ExecWithStdin runs a command inside a container with stdin piped from the provided byte slice. Arguments are passed directly to docker exec without shell wrapping, making it safe for structured input (e.g. JSON).

Jump to

Keyboard shortcuts

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