Documentation
¶
Overview ¶
Package runtime provides the container runtime.
Index ¶
- func ApplyAppArmor(profileName string) error
- func ApplySeccomp(profilePath string) error
- func DetectBox64() bool
- func DetectFEXEmu() bool
- func DetectGVisor() bool
- func DetectSysbox() bool
- func DetectWAMR() bool
- func DetectWasmEdge() bool
- func Logger(component string) *slog.Logger
- func PidfdAvailable() bool
- type CPUStats
- type Config
- type ContainerJSON
- type ContainerRunner
- type ContainerState
- type ContainerStats
- type ExecConfig
- type ExecutionMode
- type HealthCheckConfig
- type ImageOCIConfig
- type MemoryStats
- type NetworkStats
- type PidfdMonitor
- type PidfdProcessGroup
- func (pg *PidfdProcessGroup) CloseAll()
- func (pg *PidfdProcessGroup) Remove(pid int)
- func (pg *PidfdProcessGroup) Signal(pid int, sig syscall.Signal) error
- func (pg *PidfdProcessGroup) SignalAll(sig syscall.Signal) []error
- func (pg *PidfdProcessGroup) Track(pid int) error
- func (pg *PidfdProcessGroup) Tracked() []int
- type Registry
- type Resources
- type RunnerCapabilities
- type RunnerInfo
- type Runtime
- func (rt *Runtime) Create(cfg *Config) (*ContainerState, error)
- func (rt *Runtime) Delete(id string, force bool) error
- func (rt *Runtime) Exec(id string, args []string, env []string, workingDir, user string) ([]byte, []byte, error)
- func (rt *Runtime) GetLogs(id string, tail int) (string, error)
- func (rt *Runtime) Kill(id string, signal syscall.Signal) error
- func (rt *Runtime) List() ([]*ContainerState, error)
- func (rt *Runtime) Mode() ExecutionMode
- func (rt *Runtime) Pause(id string) error
- func (rt *Runtime) Processes(id string) ([]string, error)
- func (rt *Runtime) Registry() *Registry
- func (rt *Runtime) SaveState(state *ContainerState) error
- func (rt *Runtime) Start(id string) error
- func (rt *Runtime) StartHealthcheck(id string, cmd []string, interval, timeout time.Duration, retries int)
- func (rt *Runtime) State(id string) (*ContainerState, error)
- func (rt *Runtime) Stats(id string) (map[string]interface{}, error)
- func (rt *Runtime) Stop(id string, timeout int) error
- func (rt *Runtime) Unpause(id string) error
- type RuntimeOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyAppArmor ¶
ApplyAppArmor applies an AppArmor profile to a container. KNOWN ISSUE: This writes to /proc/self/attr/current which only affects the calling goroutine, not the actual container process. A correct implementation requires writing to /proc/<pid>/attr/current after the container process has started, which requires an architecture change to defer profile application until after fork/exec.
func ApplySeccomp ¶
ApplySeccomp applies a seccomp profile to the current process (for use before exec).
func PidfdAvailable ¶ added in v0.10.0
func PidfdAvailable() bool
Types ¶
type Config ¶
type Config struct {
ID string
Rootfs string
Args []string
Env []string
Cwd string
User string
Tty bool
Interactive bool
Privileged bool
ReadOnly bool
NetworkMode common.NetworkMode
Hostname string
Labels map[string]string
Annotations map[string]string
Mounts []common.Mount
Ports []common.Port
DNS []string
DNSSearch []string
DNSOptions []string
ExtraHosts []string
CapAdd []string
CapDrop []string
SecurityOpt []string
Sysctls map[string]string
Resources *Resources
StopSignal string
StopTimeout int
Init bool
RestartPolicy common.RestartPolicy
RestartMaxRetries int
HealthCheck *HealthCheckConfig
Runtime string
LogDriver common.LogDriver
ImageRef string
ImageDigest string
ImageLayers []string // paths to image layer tarballs
ImageConfig *ImageOCIConfig
RootfsReady string // path to extracted rootfs
Platform string // "linux/arm64", "linux/amd64", "wasi/wasm", etc.
}
Config holds the configuration for a container.
type ContainerJSON ¶
type ContainerJSON struct {
ID string
Pid int
Status string
Config *Config
RootfsPath string
LogPath string
Mode ExecutionMode
RestartCount int
CreatedAt time.Time
StartedAt time.Time
FinishedAt time.Time
ExitCode int
GuestArch string // For cross-arch modes
IsolationType string // "hardware", "user-space", "none"
}
ContainerJSON holds full container information for inspect.
type ContainerRunner ¶
type ContainerRunner interface {
// Name returns the execution mode this runner implements.
Name() ExecutionMode
// Detect returns true if this runner can work on the current host.
// Called once at startup to build the registry.
Detect() bool
// Capabilities returns what this runner supports.
Capabilities() RunnerCapabilities
// Create prepares the container filesystem, config, OCI spec.
// Returns the container ID. Does NOT start the process.
Create(ctx context.Context, cfg *Config) (string, error)
// Start launches the container process. Returns the PID (or 0 for WASM).
Start(ctx context.Context, id string) (int, error)
// Stop sends a signal to the container. timeout=0 → SIGKILL.
Stop(ctx context.Context, id string, timeout time.Duration) error
// Exec runs a new process inside a running container.
Exec(ctx context.Context, id string, cfg *ExecConfig) (int, error)
// Kill sends an arbitrary signal to the container.
Kill(ctx context.Context, id string, sig syscall.Signal) error
// Pause suspends the container (cgroup freezer, SIGSTOP, or VM suspend).
Pause(ctx context.Context, id string) error
// Resume resumes a paused container.
Resume(ctx context.Context, id string) error
// Wait blocks until the container exits and returns the exit code.
Wait(ctx context.Context, id string) (int, error)
// Stats returns resource usage (CPU, memory, I/O).
Stats(ctx context.Context, id string) (*ContainerStats, error)
// Inspect returns full container metadata.
Inspect(ctx context.Context, id string) (*ContainerJSON, error)
// Cleanup removes all resources (rootfs, state, tmp files).
Cleanup(ctx context.Context, id string) error
}
ContainerRunner is the contract for any execution mode. Implementations must be goroutine-safe and support context cancellation.
type ContainerState ¶
type ContainerState struct {
ID string `json:"id"`
Pid int `json:"pid"`
Status common.ContainerState `json:"status"`
Created time.Time `json:"created"`
Started time.Time `json:"started,omitempty"`
Finished time.Time `json:"finished,omitempty"`
ExitCode int `json:"exitCode,omitempty"`
Bundle string `json:"bundle"`
Config *Config `json:"config,omitempty"`
PidPath string `json:"pidPath,omitempty"`
LogPath string `json:"logPath,omitempty"`
Mode ExecutionMode `json:"mode"`
RestartCount int `json:"restartCount,omitempty"`
HealthStatus *common.HealthStatus `json:"healthStatus,omitempty"`
ExitChan chan struct{} `json:"-"`
Cmd *exec.Cmd `json:"-"`
}
ContainerState represents the current state of a container persisted to disk.
type ContainerStats ¶
type ContainerStats struct {
CPU CPUStats
Memory MemoryStats
Network NetworkStats
PIDs int
}
ContainerStats holds resource usage for a container.
type ExecConfig ¶
type ExecConfig struct {
ID string
ContainerID string
Args []string
Env []string
WorkingDir string
User string
Tty bool
AttachStdin bool
AttachStdout bool
AttachStderr bool
Privileged bool
}
ExecConfig holds configuration for exec into a running container.
type ExecutionMode ¶
type ExecutionMode int
ExecutionMode defines how a container process is run.
const ( ModeNative ExecutionMode = iota // 0: Direct host execution ModeProot // 1: proot-based isolation ModeNamespaces // 2: Full Linux namespace isolation ModeMicroVM // 3: Hardware-level isolation via microVM ModeGVisor // 4: gVisor systrap user-space kernel ModeWASM // 5: WasmEdge/WAMR/Wasmtime WASI containers ModePkDroid // 6: pKVM hardware isolation + Microdroid ModeSysbox // 7: Rootless DinD via sysbox-runc ModeQEMUUser // 8: QEMU user-mode cross-arch emulation ModeChroot // 9: Lightweight chroot isolation ModeFEX // 10: FEX-Emu/Box64 x86 emulation on ARM64 ModeLegacy32 // 11: Dual-arch ARMv7/ARM64 containers )
func AllExecutionModes ¶
func AllExecutionModes() []ExecutionMode
AllExecutionModes returns all supported execution modes.
func ParseExecutionMode ¶
func ParseExecutionMode(s string) (ExecutionMode, bool)
ParseExecutionMode parses a mode name string into an ExecutionMode.
func (ExecutionMode) String ¶
func (m ExecutionMode) String() string
String returns the human-readable name of the execution mode.
type HealthCheckConfig ¶
type HealthCheckConfig struct {
Test []string
Interval time.Duration
Timeout time.Duration
Retries int
}
HealthCheckConfig defines the health check parameters for a container.
type ImageOCIConfig ¶
type ImageOCIConfig struct {
Entrypoint []string
Cmd []string
Env []string
WorkingDir string
User string
Volumes map[string]struct{}
Labels map[string]string
StopSignal string
Shell []string
HealthCheck *HealthCheckConfig
}
ImageOCIConfig represents the OCI image configuration extracted from an image manifest.
type MemoryStats ¶
MemoryStats holds memory usage.
type NetworkStats ¶
NetworkStats holds network I/O.
type PidfdMonitor ¶ added in v0.10.0
type PidfdMonitor struct {
// contains filtered or unexported fields
}
func NewPidfdMonitor ¶ added in v0.10.0
func NewPidfdMonitor(pid int) (*PidfdMonitor, error)
func (*PidfdMonitor) Close ¶ added in v0.10.0
func (m *PidfdMonitor) Close() error
func (*PidfdMonitor) PID ¶ added in v0.10.0
func (m *PidfdMonitor) PID() int
func (*PidfdMonitor) PidFD ¶ added in v0.10.0
func (m *PidfdMonitor) PidFD() int
func (*PidfdMonitor) Signal ¶ added in v0.10.0
func (m *PidfdMonitor) Signal(sig syscall.Signal) error
func (*PidfdMonitor) Wait ¶ added in v0.10.0
func (m *PidfdMonitor) Wait() (int, error)
type PidfdProcessGroup ¶ added in v0.10.0
type PidfdProcessGroup struct {
// contains filtered or unexported fields
}
func NewPidfdProcessGroup ¶ added in v0.10.0
func NewPidfdProcessGroup() *PidfdProcessGroup
func (*PidfdProcessGroup) CloseAll ¶ added in v0.10.0
func (pg *PidfdProcessGroup) CloseAll()
func (*PidfdProcessGroup) Remove ¶ added in v0.10.0
func (pg *PidfdProcessGroup) Remove(pid int)
func (*PidfdProcessGroup) Signal ¶ added in v0.10.0
func (pg *PidfdProcessGroup) Signal(pid int, sig syscall.Signal) error
func (*PidfdProcessGroup) SignalAll ¶ added in v0.10.0
func (pg *PidfdProcessGroup) SignalAll(sig syscall.Signal) []error
func (*PidfdProcessGroup) Track ¶ added in v0.10.0
func (pg *PidfdProcessGroup) Track(pid int) error
func (*PidfdProcessGroup) Tracked ¶ added in v0.10.0
func (pg *PidfdProcessGroup) Tracked() []int
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages all available container runners and selects the best one for a given configuration.
func (*Registry) AllRunners ¶
func (r *Registry) AllRunners() []RunnerInfo
AllRunners returns info about all known modes (available and unavailable).
func (*Registry) Available ¶
func (r *Registry) Available() []RunnerInfo
Available returns all detected runners with their info.
func (*Registry) BestFor ¶
func (r *Registry) BestFor(cfg *Config) ContainerRunner
BestFor selects the optimal runner for the given configuration. Priority chain:
- Explicit --runtime flag (cfg.Runtime)
- WASM images → ModeWASM
- Cross-arch platform → ModeQEMUUser or ModeFEX
- Root available → ModeNamespaces or ModeChroot
- KVM available → ModeMicroVM
- gVisor available → ModeGVisor
- pKVM available → ModePkDroid
- proot available → ModeProot
- Fallback → ModeNative
func (*Registry) Get ¶
func (r *Registry) Get(mode ExecutionMode) ContainerRunner
Get returns the runner for the given mode, or nil if not available.
func (*Registry) Register ¶
func (r *Registry) Register(runner ContainerRunner)
Register adds a runner to the registry if it's available on this host.
type Resources ¶
type Resources struct {
Memory int64
MemorySwap int64
NanoCpus int64
CPUPeriod int64
CPUQuota int64
CpusetCpus string
CpusetMems string
PidsLimit int64
BlkioWeight uint16
OomKillDisable bool
ShmSize int64
}
Resources defines the resource limits for a container.
type RunnerCapabilities ¶
type RunnerCapabilities struct {
Arch []string // Architectures this runner can execute on
RootRequired bool // Needs root/sudo to function
KVMRequired bool // Needs /dev/kvm
CrossArch bool // Can run foreign-arch binaries
WASM bool // Is a WASM runtime
HWIsolation bool // Hardware-enforced isolation
PauseSupport bool // Supports pause/resume
ExecSupport bool // Supports exec into running container
StatsSupport bool // Supports resource stats
DinDCapable bool // Can run Docker inside the container
MaxContainers int // 0 = unlimited
GuestArch []string // For cross-arch: which guest archs are supported
}
RunnerCapabilities describes what a runner supports.
type RunnerInfo ¶
type RunnerInfo struct {
Mode ExecutionMode
Name string
Capabilities RunnerCapabilities
Available bool
}
RunnerInfo holds information about a detected runner.
type Runtime ¶
type Runtime struct {
// contains filtered or unexported fields
}
Runtime implements the OCI Runtime Specification.
func NewRuntime ¶
func NewRuntime(root string, store *storage.Manager, opts ...RuntimeOption) *Runtime
NewRuntime creates a new container runtime instance.
func (*Runtime) Create ¶
func (rt *Runtime) Create(cfg *Config) (*ContainerState, error)
Create creates a new container with the given configuration.
func (*Runtime) Exec ¶
func (rt *Runtime) Exec(id string, args []string, env []string, workingDir, user string) ([]byte, []byte, error)
Exec runs a command inside a running container.
func (*Runtime) GetLogs ¶
GetLogs returns the logs of a container, optionally tailing the last N lines.
func (*Runtime) List ¶
func (rt *Runtime) List() ([]*ContainerState, error)
List returns all containers managed by the runtime.
func (*Runtime) Mode ¶
func (rt *Runtime) Mode() ExecutionMode
Mode returns the current execution mode of the runtime.
func (*Runtime) SaveState ¶ added in v0.9.3
func (rt *Runtime) SaveState(state *ContainerState) error
SaveState persists the container state to disk.
func (*Runtime) StartHealthcheck ¶
func (rt *Runtime) StartHealthcheck(id string, cmd []string, interval, timeout time.Duration, retries int)
StartHealthcheck begins periodic health checks for a container.
func (*Runtime) State ¶
func (rt *Runtime) State(id string) (*ContainerState, error)
State returns the current state of a container.
type RuntimeOption ¶
type RuntimeOption func(*Runtime)
RuntimeOption is a functional option for NewRuntime.
func WithDNSAddr ¶
func WithDNSAddr(addr string) RuntimeOption
WithDNSAddr sets the internal DNS server address for container resolv.conf.
func WithRegistry ¶
func WithRegistry(reg *Registry) RuntimeOption
WithRegistry sets the runner registry for the runtime.
Directories
¶
| Path | Synopsis |
|---|---|
|
runners
|
|
|
chroot
Package chroot implements the lightweight chroot container runner.
|
Package chroot implements the lightweight chroot container runner. |
|
fex
Package fex implements the FEX-Emu/Box64 container runner for x86 emulation on ARM64.
|
Package fex implements the FEX-Emu/Box64 container runner for x86 emulation on ARM64. |
|
gvisor
Package gvisor implements the gVisor container runner.
|
Package gvisor implements the gVisor container runner. |
|
legacy32
Package legacy32 implements the dual-arch ARMv7/ARM64 container runner.
|
Package legacy32 implements the dual-arch ARMv7/ARM64 container runner. |
|
microvm
Package microvm implements the microVM container runner.
|
Package microvm implements the microVM container runner. |
|
namespaces
Package namespaces implements the Linux namespaces container runner.
|
Package namespaces implements the Linux namespaces container runner. |
|
native
Package native implements the native container runner.
|
Package native implements the native container runner. |
|
pkdroid
Package pkdroid implements the pKVM hardware isolation container runner.
|
Package pkdroid implements the pKVM hardware isolation container runner. |
|
proot
Package proot implements the proot container runner.
|
Package proot implements the proot container runner. |
|
qemuuser
Package qemuuser implements the QEMU user-mode cross-arch container runner.
|
Package qemuuser implements the QEMU user-mode cross-arch container runner. |
|
sysbox
Package sysbox implements the rootless DinD container runner.
|
Package sysbox implements the rootless DinD container runner. |
|
wasm
Package wasm implements the WASM/WASI container runner.
|
Package wasm implements the WASM/WASI container runner. |