runtime

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package runtime provides an abstraction over container runtimes (Docker, containerd).

Index

Constants

View Source
const (

	// RuntimeDocker selects the Docker SDK runtime.
	RuntimeDocker = "docker"
	// RuntimeContainerd is a backward-compatible alias that uses nerdctl via the ctrctl CLI wrapper.
	RuntimeContainerd = "containerd"
	// RuntimeAuto auto-detects the available runtime (Docker SDK preferred, then CLI auto-detection).
	RuntimeAuto = "auto"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ContainerInfo

type ContainerInfo struct {
	// Image is the container image reference.
	Image string
	// Env is the list of environment variables in "KEY=VALUE" format.
	Env []string
	// Cmd is the command to run in the container.
	Cmd []string
	// Tty indicates whether a TTY is allocated.
	Tty bool
	// AttachStdout indicates whether stdout is attached.
	AttachStdout bool
	// AttachStderr indicates whether stderr is attached.
	AttachStderr bool
	// Privileged indicates whether the container runs in privileged mode.
	Privileged bool
	// Binds is the list of volume bind mounts in "host:container" format.
	Binds []string
	// PidMode is the PID namespace mode (e.g., "host").
	PidMode string
	// Snapshotter is the containerd snapshotter name (e.g., "overlayfs"). Only used by containerd runtime.
	Snapshotter string
}

ContainerInfo holds runtime-agnostic container configuration. It is used to inspect the current container and to create new containers.

type CtrctlFactory

type CtrctlFactory func(cli []string) (Runtime, error)

CtrctlFactory creates a ctrctl-backed runtime client using the given CLI command.

type DockerFactory

type DockerFactory func() (Runtime, error)

DockerFactory creates a Docker runtime client using the Docker SDK.

type Pingable

type Pingable interface {
	Ping(ctx context.Context) error
}

Pingable is an optional interface that runtime implementations can satisfy to verify daemon connectivity.

type Runtime

type Runtime interface {
	// InspectSelf returns the container configuration for the current container.
	// The runtime is responsible for detecting which container it is running in.
	InspectSelf(ctx context.Context) (ContainerInfo, error)
	// RunContainer creates and starts a new container with the given configuration.
	RunContainer(ctx context.Context, info ContainerInfo) error
	// ImageExists checks if the given image reference exists locally.
	ImageExists(ctx context.Context, imageRef string) bool
	// PullImage pulls the given image reference from a registry.
	PullImage(ctx context.Context, imageRef string) error
	// Close cleans up the runtime client resources.
	Close() error
}

Runtime is the interface that container runtimes must implement.

func Detect

func Detect(preference string, dockerFn DockerFactory, ctrctlFn CtrctlFactory, nerdctlNamespace string, nsenterHost bool) (Runtime, error)

Detect selects and creates a runtime client based on the preference string.

Preference values:

  • "docker": use Docker SDK, fail if unavailable
  • "containerd": alias for nerdctl via the ctrctl CLI wrapper (backward compat)
  • "auto" or "": auto-detect (Docker SDK preferred, then CLI auto-detection)

nerdctlNamespace is the containerd namespace passed to nerdctl via --namespace. It is only applied when the resolved CLI is nerdctl.

When nsenterHost is true, nerdctl CLI invocations are prefixed with nsenter -t 1 -m -u -i -n -p -- so they execute inside all host namespaces. The nerdctl binary path is changed to /tmp/nerdctl (staged there by main). This has no effect on the Docker SDK path.

The dockerFn and ctrctlFn factories construct the actual clients, keeping this function decoupled from the concrete implementations.

Directories

Path Synopsis
Package docker implements the runtime.Runtime interface using the Docker Engine API.
Package docker implements the runtime.Runtime interface using the Docker Engine API.
Package nerdctl implements the runtime.Runtime interface using the ctrctl CLI wrapper.
Package nerdctl implements the runtime.Runtime interface using the ctrctl CLI wrapper.

Jump to

Keyboard shortcuts

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