Help us shape the future of Go! Take the 2026 Go Developer Survey

container

package
v0.33.1 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DriverDocker = "docker"
	DriverPodman = "podman"
	DriverApple  = "apple"
)
View Source
const (
	LibraryName = "scriptling.container"
	LibraryDesc = "Container management library supporting Docker, Podman, and Apple Containers"

	DefaultDockerSocket = "/var/run/docker.sock"
	DefaultPodmanSocket = "/var/run/podman.sock"

	// DefaultAppleCLI is where Apple's installer puts the `container` CLI.
	// The Apple driver runs it from this fixed path rather than looking it
	// up on PATH, where a script able to write to a PATH directory could
	// put a program of the same name. Like the Docker and Podman endpoints,
	// it is the operator's, so it is used even where scripts may not start
	// processes themselves.
	DefaultAppleCLI = "/usr/local/bin/container"
)

Variables

This section is empty.

Functions

func Register

func Register(registrar interface{ RegisterLibrary(*object.Library) }, dockerSock, podmanSock string)

Register registers the scriptling.container library with the given registrar. dockerSock and podmanSock override the default socket paths (empty = use default).

func RegisterConfigured added in v0.33.0

func RegisterConfigured(registrar interface{ RegisterLibrary(*object.Library) }, dockerSock, podmanSock string, paths fssecurity.Config, policy *netsecurity.Config)

RegisterConfigured is Register with restrictions on endpoints a script supplies through Client(socket=...): a Unix socket path must lie within paths, and a TCP/HTTP(S) endpoint must pass the network policy. The operator's endpoints (dockerSock, podmanSock or the defaults) are trusted and never checked. See RegisterWithOptions for what run() enforces.

func RegisterWithOptions added in v0.33.0

func RegisterWithOptions(registrar interface{ RegisterLibrary(*object.Library) }, opts Options)

RegisterWithOptions registers the scriptling.container library configured by opts.

Types

type ContainerDriver

type ContainerDriver interface {
	// Login authenticates with a container registry.
	Login(ctx context.Context, server, username, password string) error

	// Pull fetches an image from a registry.
	Pull(ctx context.Context, image string) error

	// Exec runs a command inside a running container and captures output.
	Exec(ctx context.Context, nameOrID string, command []string, opts ExecOptions) (*ExecResult, error)

	// ExecStream runs a command inside a running container, calling fn for each output line.
	ExecStream(ctx context.Context, nameOrID string, command []string, opts ExecOptions, fn func(stream, line string)) (*ExecResult, error)

	// ImageList returns locally available images.
	ImageList(ctx context.Context) ([]ImageInfo, error)

	// ImageRemove removes a local image.
	ImageRemove(ctx context.Context, image string) error

	// Run creates and starts a container, returning its ID.
	Run(ctx context.Context, image string, opts RunOptions) (string, error)

	// Stop stops a running container (graceful then force).
	Stop(ctx context.Context, nameOrID string) error

	// WaitStopped polls until the container is no longer running, or the
	// timeout elapses. Returns true if the container reached a stopped
	// state, false if the timeout was hit first. An error is returned if
	// the container cannot be found/inspected for reasons other than "not
	// running" (e.g. it was fully removed while waiting is treated as stopped).
	WaitStopped(ctx context.Context, nameOrID string, timeout time.Duration) (bool, error)

	// Remove removes a stopped container.
	Remove(ctx context.Context, nameOrID string) error

	// Inspect returns details about a container.
	Inspect(ctx context.Context, nameOrID string) (*ContainerInfo, error)

	// List returns all containers (running and stopped).
	List(ctx context.Context) ([]ContainerInfo, error)

	// VolumeCreate creates a named volume. size is optional (e.g. "20G") and
	// only honoured by Apple Containers; other drivers silently ignore it.
	VolumeCreate(ctx context.Context, name, size string) error

	// VolumeRemove removes a named volume.
	VolumeRemove(ctx context.Context, name string) error

	// VolumeList returns all named volumes.
	VolumeList(ctx context.Context) ([]string, error)
}

ContainerDriver is the interface every runtime driver must implement.

type ContainerInfo

type ContainerInfo struct {
	ID      string
	Name    string
	Status  string
	Image   string
	Running bool
}

ContainerInfo is the common container representation returned by inspect/list.

type ExecOptions

type ExecOptions struct {
	Env     []string
	WorkDir string
	User    string
}

ExecOptions holds optional parameters for Exec / ExecStream.

type ExecResult

type ExecResult struct {
	Stdout   string
	Stderr   string
	ExitCode int
}

ExecResult holds the output of a completed exec.

type ImageInfo

type ImageInfo struct {
	ID        string
	Reference string
	Digest    string
	Size      int64
}

ImageInfo is the common image representation returned by image_list.

type Options added in v0.33.0

type Options struct {
	// DockerSock and PodmanSock override the default operator endpoints
	// (empty = default). They are trusted and never checked.
	DockerSock, PodmanSock string

	// AppleCLI is the absolute path of Apple's `container` CLI (empty =
	// DefaultAppleCLI). It is never looked up on PATH.
	AppleCLI string

	// Paths is the filesystem jail. When it restricts paths, a Unix socket a
	// script names in Client(socket=...) and every host path a script binds
	// into a container with run(volumes=...) must lie within it.
	Paths fssecurity.Config

	// Policy is the network policy. When set, a TCP/HTTP(S) endpoint a
	// script names in Client(socket=...) must pass it, and run() refuses
	// network="host", which would give the container the host's loopback
	// services.
	Policy *netsecurity.Config

	// DenyPrivileged refuses run(privileged=True). Privileged containers are
	// allowed by default; a privileged container can reach every host device
	// and disk, so set this where scripts must not control the host.
	DenyPrivileged bool
}

Options configures RegisterWithOptions. The zero value registers the library with no restrictions, as Register does.

type RunOptions

type RunOptions struct {
	Name       string
	Ports      []string // "hostPort:containerPort"
	Env        []string // "KEY=value"
	Volumes    []string // "name:/path" or "/host:/container"
	Command    []string
	Privileged bool
	Network    string
}

RunOptions holds parameters for starting a container.

Jump to

Keyboard shortcuts

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