runtime

package
v0.0.4 Latest Latest
Warning

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

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

Documentation

Overview

Package runtime provides a container runtime abstraction for Docker and Podman. Both runtimes share a compatible CLI interface, so a single implementation handles both via os/exec.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Detect

func Detect() (string, error)

Detect returns the name of the first available container runtime. It prefers podman over docker when both are available, consistent with the convention that rootless podman is the safer default.

Types

type BuildOptions added in v0.0.4

type BuildOptions struct {
	// Tag is the image tag to build.
	Tag string
	// Dockerfile is the path to the Dockerfile.
	Dockerfile string
	// Context is the build context directory.
	Context string
}

BuildOptions configures an image build invocation.

type ContainerInfo

type ContainerInfo struct {
	ID        string    `json:"id"`
	Name      string    `json:"name"`
	Image     string    `json:"image"`
	Status    string    `json:"status"`
	StartedAt time.Time `json:"startedAt"`
}

ContainerInfo holds information about a running container.

type RunOptions

type RunOptions struct {
	// Name is the container name.
	Name string
	// Image is the container image reference.
	Image string
	// Detach runs the container in background.
	Detach bool
	// User overrides the container user (e.g. "1000:1000").
	// This is essential for bind mounts so the container process matches
	// the host UID that owns the mounted files.
	User string
	// EnvVars are environment variables to set.
	EnvVars map[string]string
	// Volumes are bind mount specifications.
	Volumes []Volume
	// Ports maps host ports to container ports.
	Ports map[int]int
}

RunOptions configures a container run invocation.

type Runtime

type Runtime interface {
	// Name returns the runtime name ("docker" or "podman").
	Name() string
	// Run starts a new container and returns its ID.
	Run(ctx context.Context, opts RunOptions) (string, error)
	// Stop stops a running container.
	Stop(ctx context.Context, name string) error
	// Remove removes a container.
	Remove(ctx context.Context, name string) error
	// Status returns the container status ("running", "exited", "created", etc.)
	// or an empty string if the container doesn't exist.
	Status(ctx context.Context, name string) (string, error)
	// Inspect returns detailed container information.
	Inspect(ctx context.Context, name string) (*ContainerInfo, error)
	// Logs streams container logs to stdout/stderr. If follow is true, it
	// streams continuously until interrupted. If tail > 0, only the last N
	// lines are shown.
	Logs(ctx context.Context, name string, follow bool, tail int) error
	// BuildImage builds a container image from a Dockerfile.
	// Returns the image tag on success.
	BuildImage(ctx context.Context, opts BuildOptions) (string, error)
	// ImageExists checks if an image tag exists locally.
	ImageExists(ctx context.Context, tag string) (bool, error)
}

Runtime is the interface for managing container lifecycle operations.

func New

func New(name string) (Runtime, error)

New creates a runtime for the given name ("docker" or "podman"). If name is empty, it auto-detects the available runtime.

type Volume

type Volume struct {
	// HostPath is the path on the host.
	HostPath string
	// ContainerPath is the path inside the container.
	ContainerPath string
	// ReadOnly marks the mount as read-only.
	ReadOnly bool
}

Volume represents a bind mount.

Jump to

Keyboard shortcuts

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