Documentation
¶
Overview ¶
Package runtime provides an abstraction over container runtimes (Docker, nerdctl).
Index ¶
Constants ¶
const ( // RuntimeDocker selects the Docker SDK runtime. RuntimeDocker = "docker" // RuntimeNerdctl selects the nerdctl CLI runtime via the ctrctl wrapper. RuntimeNerdctl = "nerdctl" // 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 nerdctl runtime.
Snapshotter string
}
ContainerInfo holds runtime-agnostic container configuration. It is used to inspect the current container and to create new containers.
type DockerRuntime ¶ added in v0.4.3
DockerRuntime creates a Docker runtime client using the Docker SDK.
type NerdctlRuntime ¶ added in v0.4.3
NerdctlRuntime creates a ctrctl-backed runtime client using the given CLI command.
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 DockerRuntime, nerdctlFn NerdctlRuntime, 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
- "nerdctl": use nerdctl via the ctrctl CLI wrapper
- "auto" or "": auto-detect (Docker SDK preferred, then nerdctl)
nerdctlNamespace is the 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. nerdctl must already be installed on the host. This has no effect on the Docker SDK path.
The dockerFn and nerdctlFn 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. |