Documentation
¶
Overview ¶
Package runtime provides the container runtime.
Index ¶
- func ApplyAppArmor(profileName string) error
- func ApplySeccomp(profilePath string) error
- func BuildCommand(reqEntrypoint, reqCmd []string, img *ImageOCIConfig) []string
- 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 AttachSession
- type CPUStats
- type Config
- type ContainerJSON
- type ContainerRunner
- type ContainerState
- type ContainerStats
- type ContainerStatsData
- type ExecConfig
- type ExecResult
- type ExecutionMode
- type ExecutionModeInfo
- type HealthCheckConfig
- type HealthChecker
- type ImageOCIConfig
- type LinuxResources
- 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) AttachStreams(id string) (*AttachSession, error)
- func (rt *Runtime) CgroupsAvailable() bool
- func (rt *Runtime) ContainerStats(id string) (*ContainerStatsData, error)
- 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) ExecAttach(containerID string, args []string, env []string, workingDir, user string, ...) (*ExecResult, error)
- func (rt *Runtime) GetLogs(id string, tail int) (string, error)
- func (rt *Runtime) IsInteractive(id string) bool
- 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) ResizeTTY(id string, rows, cols uint16) error
- 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
- func (rt *Runtime) UpdateResources(id string, res *LinuxResources) 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 BuildCommand ¶ added in v0.12.0
func BuildCommand(reqEntrypoint, reqCmd []string, img *ImageOCIConfig) []string
BuildCommand resolves the final argv for a container from the caller's entrypoint/cmd and the image's own defaults, applying Docker's override rules: an explicit entrypoint replaces the image's, an explicit cmd replaces the image's, and a shell-form entrypoint string gets wrapped in `sh -c`.
Both the Docker and the libpod surfaces call this so the two can never drift into resolving the same image to different commands.
func PidfdAvailable ¶ added in v0.10.0
func PidfdAvailable() bool
Types ¶
type AttachSession ¶ added in v0.12.0
type AttachSession struct {
Tty bool
Stdin io.WriteCloser // nil if the container is not interactive
Stdout io.ReadCloser
Stderr io.ReadCloser // nil in TTY mode (output is combined)
// contains filtered or unexported fields
}
AttachSession is the live-stdio handle the API layer streams to a client.
func (*AttachSession) Detach ¶ added in v0.12.0
func (a *AttachSession) Detach()
Detach releases the session's resources. Safe to call more than once.
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:"-"`
// contains filtered or unexported fields
}
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 ContainerStatsData ¶ added in v0.12.0
type ContainerStatsData struct {
ID string
CPUUsageNS uint64
CPUUserNS uint64
CPUKernelNS uint64
MemoryBytes uint64
MemoryLimit uint64
PidsCurrent uint64
PidsLimit uint64
BlockIORB uint64
BlockIOWB uint64
BlockIORIOs uint64
BlockIOWIOs uint64
CPUSomePSI float64
MemorySomePSI float64
IOSomePSI float64
Timestamp int64
}
ContainerStatsData is a portable, CRI-agnostic stats payload suitable for translation to v1.ContainerStats by the CRI server.
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 ExecResult ¶ added in v0.12.0
type ExecResult struct {
Stdin io.WriteCloser
Stdout io.ReadCloser
Stderr io.ReadCloser
Wait func() error // blocks until process exits and returns exit error
Pid int
}
ExecResult holds the result of a streaming exec call.
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) Info ¶ added in v0.11.1
func (m ExecutionMode) Info() ExecutionModeInfo
Info returns user-facing metadata for an execution mode.
func (ExecutionMode) String ¶
func (m ExecutionMode) String() string
String returns the human-readable name of the execution mode.
type ExecutionModeInfo ¶ added in v0.11.1
type ExecutionModeInfo struct {
Mode ExecutionMode
Name string
Level int
Isolation string
Platforms []string
Description string
}
ExecutionModeInfo describes a runtime mode in user-facing terms. Level is a rough isolation strength score where higher means stronger isolation.
func ExecutionModeInfos ¶ added in v0.11.1
func ExecutionModeInfos() []ExecutionModeInfo
ExecutionModeInfos returns metadata for every known execution mode sorted by descending isolation level.
type HealthCheckConfig ¶
type HealthCheckConfig struct {
Test []string
Interval time.Duration
Timeout time.Duration
Retries int
StartPeriod time.Duration
StartInterval time.Duration
}
HealthCheckConfig defines the health check parameters for a container.
type HealthChecker ¶ added in v0.11.0
type HealthChecker struct {
// contains filtered or unexported fields
}
HealthChecker periodically executes a health check probe for a container and updates the container's HealthStatus in its persisted state.
func NewHealthChecker ¶ added in v0.11.0
func NewHealthChecker(rt *Runtime, id string, cfg *HealthCheckConfig) *HealthChecker
NewHealthChecker creates a HealthChecker for the given container.
func (*HealthChecker) Start ¶ added in v0.11.0
func (hc *HealthChecker) Start()
Start launches the health check goroutine.
func (*HealthChecker) Stop ¶ added in v0.11.0
func (hc *HealthChecker) Stop()
Stop signals the health check goroutine to exit and blocks until it does. Safe to call multiple times.
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 LinuxResources ¶ added in v0.12.0
type LinuxResources struct {
// CPU
CPUQuota int64 // microseconds per period (0 = unset)
CPUPeriod uint64 // microseconds (default 100000)
NanoCPUs int64 // 1e9 = 1 CPU
CpusetCpus string
CpusetMems string
// Memory (bytes)
Memory int64
MemorySwap int64
MemorySwappiness *uint64
// PIDs
PidsLimit int64
// Block I/O
BlkioWeight uint16
// OOM
OomKillDisable bool
}
LinuxResources is a portable representation of cgroup resource limits. It maps to LinuxContainerResources in the CRI spec, and is also used by /containers/{id}/update.
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. Selection order:
- Explicit cfg.Runtime or DOKI_RUNTIME override.
- Workload-specific modes (WASM, foreign architecture).
- Highest available isolation level compatible with the host.
- Native fallback.
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) AttachStreams ¶ added in v0.12.0
func (rt *Runtime) AttachStreams(id string) (*AttachSession, error)
AttachStreams returns a live-stdio session for an interactive container, or an error if the container has no broker (not started interactively, or already exited). The caller must Detach the session when done.
func (*Runtime) CgroupsAvailable ¶ added in v0.12.0
CgroupsAvailable reports whether cgroup v2 limits can actually be enforced on this host. Handlers use it to warn instead of silently accepting resource changes that will never take effect.
func (*Runtime) ContainerStats ¶ added in v0.12.0
func (rt *Runtime) ContainerStats(id string) (*ContainerStatsData, error)
ContainerStats returns a portable stats payload for a single container, sourced from cgroup v2. The CRI server translates this to v1.ContainerStats.
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) ExecAttach ¶ added in v0.12.0
func (rt *Runtime) ExecAttach(containerID string, args []string, env []string, workingDir, user string, tty bool) (*ExecResult, error)
ExecAttach starts a process inside a running container and returns pipes for bidirectional streaming. Unlike Exec, this does not buffer output: stdout/stderr are streamed live to the returned readers and stdin writes from the caller are forwarded to the process. The returned Wait func must be called to reap the child process.
Implementation notes:
- For ModeProot, we use proot with stdout/stderr redirected to the returned pipes.
- For ModeNamespaces, nsenter -t <pid> -m -p -a — same approach.
- For ModeNative, exec.Command directly; rootfs is the working dir.
- For VM/FEX/microvm/QEMU runners, we cannot currently inject a child process; we fall back to Exec() and synthesize a one-shot read. Callers that need real-time streaming should detect the mode and warn the user.
func (*Runtime) GetLogs ¶
GetLogs returns the logs of a container, optionally tailing the last N lines.
func (*Runtime) IsInteractive ¶ added in v0.12.0
IsInteractive reports whether a container was started with a live stdio broker (i.e. `run -it` or `run -i`), so the API layer knows whether to attach to the process or fall back to following the log file.
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) ResizeTTY ¶ added in v0.12.0
ResizeTTY applies a new window size to an interactive container's pty.
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. This is a backward-compatible wrapper that delegates to HealthChecker.
func (*Runtime) State ¶
func (rt *Runtime) State(id string) (*ContainerState, error)
State returns the current state of a container.
func (*Runtime) UpdateResources ¶ added in v0.12.0
func (rt *Runtime) UpdateResources(id string, res *LinuxResources) error
UpdateResources atomically updates cgroup v2 limits for a running container. Implements CRI UpdateContainerResources semantics: any failure rolls back the entire change set.
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.
Source Files
¶
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. |