Documentation
¶
Overview ¶
Package runtime provides an abstraction over container runtimes (Docker, containerd).
Index ¶
Constants ¶
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 ¶
CtrctlFactory creates a ctrctl-backed runtime client using the given CLI command.
type DockerFactory ¶
DockerFactory creates a Docker runtime client using the Docker SDK.
type Pingable ¶
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) (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.
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. |