container

package
v1.202.1 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RuntimeStatusMessage

func RuntimeStatusMessage(status RuntimeStatus, runtimeType Type) string

RuntimeStatusMessage returns a user-friendly message describing the runtime status.

Types

type AttachOptions

type AttachOptions struct {
	Shell     string
	ShellArgs []string
	User      string

	// IO streams for input/output. If nil, defaults to os.Stdin and iolib.Data/UI.
	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer
}

AttachOptions represents options for attaching to containers.

type BuildConfig

type BuildConfig struct {
	Dockerfile string
	Context    string
	Args       map[string]string
	Tags       []string
}

BuildConfig represents container image build configuration.

type CommandExecutor

type CommandExecutor interface {
	// LookPath searches for an executable named file in PATH.
	LookPath(file string) (string, error)

	// CommandContext creates an exec.Cmd configured to run with the given context.
	CommandContext(ctx context.Context, name string, args ...string) *exec.Cmd
}

CommandExecutor provides an abstraction for executing system commands. This interface allows for mocking command execution in unit tests.

type CreateConfig

type CreateConfig struct {
	Name            string
	Image           string
	WorkspaceFolder string
	Mounts          []Mount
	Ports           []PortBinding
	Env             map[string]string
	User            string
	Labels          map[string]string

	// Runtime configuration
	RunArgs         []string
	OverrideCommand bool     // Whether to override default command with sleep infinity
	Init            bool     // Whether to use init process
	Privileged      bool     // Run in privileged mode
	CapAdd          []string // Linux capabilities to add
	SecurityOpt     []string // Security options
}

CreateConfig represents container creation configuration.

type DockerRuntime

type DockerRuntime struct{}

DockerRuntime implements the Runtime interface for Docker.

func NewDockerRuntime

func NewDockerRuntime() *DockerRuntime

NewDockerRuntime creates a new Docker runtime.

func (*DockerRuntime) Attach

func (d *DockerRuntime) Attach(ctx context.Context, containerID string, opts *AttachOptions) error

Attach attaches to a running container with an interactive shell.

func (*DockerRuntime) Build

func (d *DockerRuntime) Build(ctx context.Context, config *BuildConfig) error

Build builds a container image from a Dockerfile.

func (*DockerRuntime) Create

func (d *DockerRuntime) Create(ctx context.Context, config *CreateConfig) (string, error)

Create creates a new container.

func (*DockerRuntime) Exec

func (d *DockerRuntime) Exec(ctx context.Context, containerID string, cmd []string, opts *ExecOptions) error

Exec executes a command in a running container.

func (*DockerRuntime) Info

func (d *DockerRuntime) Info(ctx context.Context) (*RuntimeInfo, error)

Info gets runtime information.

func (*DockerRuntime) Inspect

func (d *DockerRuntime) Inspect(ctx context.Context, containerID string) (*Info, error)

Inspect gets detailed information about a container.

func (*DockerRuntime) List

func (d *DockerRuntime) List(ctx context.Context, filters map[string]string) ([]Info, error)

List lists containers matching the given filters.

func (*DockerRuntime) Logs

func (d *DockerRuntime) Logs(ctx context.Context, containerID string, follow bool, tail string, stdout, stderr io.Writer) error

Logs shows logs from a container.

func (*DockerRuntime) Pull

func (d *DockerRuntime) Pull(ctx context.Context, image string) error

Pull pulls a container image.

func (*DockerRuntime) Remove

func (d *DockerRuntime) Remove(ctx context.Context, containerID string, force bool) error

Remove removes a container.

func (*DockerRuntime) Start

func (d *DockerRuntime) Start(ctx context.Context, containerID string) error

Start starts a container.

func (*DockerRuntime) Stop

func (d *DockerRuntime) Stop(ctx context.Context, containerID string, timeout time.Duration) error

Stop stops a running container.

type ExecOptions

type ExecOptions struct {
	User         string
	WorkingDir   string
	Env          []string
	AttachStdin  bool
	AttachStdout bool
	AttachStderr bool
	Tty          bool

	// IO streams for input/output. If nil, defaults to iolib.Data/UI.
	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer
}

ExecOptions represents options for executing commands in containers.

type Info

type Info struct {
	ID      string
	Name    string
	Image   string
	Status  string // running, stopped, exited, etc.
	Created time.Time
	Ports   []PortBinding
	Labels  map[string]string
}

Info represents container state information.

type Mount

type Mount struct {
	Type     string // bind, volume, tmpfs
	Source   string
	Target   string
	ReadOnly bool
}

Mount represents a volume mount.

type PodmanRuntime

type PodmanRuntime struct{}

PodmanRuntime implements the Runtime interface for Podman.

func NewPodmanRuntime

func NewPodmanRuntime() *PodmanRuntime

NewPodmanRuntime creates a new Podman runtime.

func (*PodmanRuntime) Attach

func (p *PodmanRuntime) Attach(ctx context.Context, containerID string, opts *AttachOptions) error

Attach attaches to a running container with an interactive shell.

func (*PodmanRuntime) Build

func (p *PodmanRuntime) Build(ctx context.Context, config *BuildConfig) error

Build builds a container image from a Dockerfile.

func (*PodmanRuntime) Create

func (p *PodmanRuntime) Create(ctx context.Context, config *CreateConfig) (string, error)

Create creates a new container.

func (*PodmanRuntime) Exec

func (p *PodmanRuntime) Exec(ctx context.Context, containerID string, cmd []string, opts *ExecOptions) error

Exec executes a command in a running container.

func (*PodmanRuntime) Info

func (p *PodmanRuntime) Info(ctx context.Context) (*RuntimeInfo, error)

Info gets runtime information.

func (*PodmanRuntime) Inspect

func (p *PodmanRuntime) Inspect(ctx context.Context, containerID string) (*Info, error)

Inspect gets detailed information about a container.

func (*PodmanRuntime) List

func (p *PodmanRuntime) List(ctx context.Context, filters map[string]string) ([]Info, error)

List lists containers matching the given filters.

func (*PodmanRuntime) Logs

func (p *PodmanRuntime) Logs(ctx context.Context, containerID string, follow bool, tail string, stdout, stderr io.Writer) error

Logs shows logs from a container.

func (*PodmanRuntime) Pull

func (p *PodmanRuntime) Pull(ctx context.Context, image string) error

Pull pulls a container image.

func (*PodmanRuntime) Remove

func (p *PodmanRuntime) Remove(ctx context.Context, containerID string, force bool) error

Remove removes a container.

func (*PodmanRuntime) Start

func (p *PodmanRuntime) Start(ctx context.Context, containerID string) error

Start starts a container.

func (*PodmanRuntime) Stop

func (p *PodmanRuntime) Stop(ctx context.Context, containerID string, timeout time.Duration) error

Stop stops a running container.

type PortBinding

type PortBinding struct {
	ContainerPort int
	HostPort      int
	Protocol      string // tcp, udp
}

PortBinding represents a port mapping.

type Runtime

type Runtime interface {
	// Lifecycle operations
	Build(ctx context.Context, config *BuildConfig) error
	Create(ctx context.Context, config *CreateConfig) (string, error)
	Start(ctx context.Context, containerID string) error
	Stop(ctx context.Context, containerID string, timeout time.Duration) error
	Remove(ctx context.Context, containerID string, force bool) error

	// State inspection
	Inspect(ctx context.Context, containerID string) (*Info, error)
	List(ctx context.Context, filters map[string]string) ([]Info, error)

	// Execution - IO streams configured via options structs
	Exec(ctx context.Context, containerID string, cmd []string, opts *ExecOptions) error
	Attach(ctx context.Context, containerID string, opts *AttachOptions) error

	// Image operations
	Pull(ctx context.Context, image string) error

	// Logs - methods that produce user-facing output accept io.Writer
	Logs(ctx context.Context, containerID string, follow bool, tail string, stdout, stderr io.Writer) error

	// Info
	Info(ctx context.Context) (*RuntimeInfo, error)
}

Runtime defines the interface for container runtime operations. This interface abstracts Docker and Podman operations for testability.

func DetectRuntime

func DetectRuntime(ctx context.Context) (Runtime, error)

DetectRuntime auto-detects the available container runtime. Priority order: 1. ATMOS_CONTAINER_RUNTIME environment variable 2. Docker (if available and running) 3. Podman (if available and running) Returns error if no runtime is available.

type RuntimeInfo

type RuntimeInfo struct {
	Type    string // docker, podman
	Version string
	Running bool
}

RuntimeInfo represents container runtime information.

type RuntimeStatus

type RuntimeStatus int

RuntimeStatus represents the availability status of a container runtime.

const (
	// RuntimeAvailable indicates the runtime is available and responsive.
	RuntimeAvailable RuntimeStatus = iota
	// RuntimeUnavailable indicates the runtime binary is not found.
	RuntimeUnavailable
	// RuntimeNotResponding indicates the runtime binary exists but is not responding.
	RuntimeNotResponding
	// RuntimeNeedsInit indicates Podman is present but needs machine initialization.
	RuntimeNeedsInit
	// RuntimeNeedsStart indicates Podman machine exists but needs to be started.
	RuntimeNeedsStart
)

func TryRecoverPodmanRuntime

func TryRecoverPodmanRuntime(ctx context.Context) RuntimeStatus

TryRecoverPodmanRuntime attempts to recover Podman by initializing/starting the machine. This is an opt-in operation that should only be called when the user explicitly requests it. Returns the new status after recovery attempt.

type Type

type Type string

Type represents the container runtime type.

const (
	// TypeDocker represents Docker runtime.
	TypeDocker Type = "docker"

	// TypePodman represents Podman runtime.
	TypePodman Type = "podman"
)

func GetRuntimeType

func GetRuntimeType(runtime Runtime) Type

GetRuntimeType returns the type of a runtime instance.

func (Type) String

func (t Type) String() string

Jump to

Keyboard shortcuts

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