daemon

package
v0.38.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: BSD-3-Clause Imports: 23 Imported by: 0

Documentation

Overview

Package daemon wires the engine together: the image store, the root filesystems built from it, and the container manager. The API server is a thin HTTP face over it.

Index

Constants

View Source
const MaxChanges = 64

MaxChanges bounds the instructions of one commit.

View Source
const ModelPrefix = "model="

ModelPrefix starts the Volume of a model mount: "model=a,b" mounts the registry models a and b read-only at the mount's target, as /a.gguf and /b.gguf.

Variables

View Source
var ErrImageInUse = errors.New("image is being used by a container")

ErrImageInUse is returned when removing an image a container uses.

View Source
var ErrNoSuchImage = errors.New("no such image")

ErrNoSuchImage is returned for an unknown image reference.

Functions

func ApplyChanges added in v0.12.0

func ApplyChanges(c image.ExecConfig, changes []string) (image.ExecConfig, error)

ApplyChanges applies `commit --change` instructions (Dockerfile syntax, one per entry) to c: CMD, ENTRYPOINT, ENV, EXPOSE, LABEL, ONBUILD, STOPSIGNAL, USER, VOLUME, WORKDIR, as Docker's commit allows. CMD and ENTRYPOINT take the JSON (exec) form or the shell form, which becomes ["/bin/sh", "-c", "…"] as in a Dockerfile.

func ExecConfig

func ExecConfig(img *image.Image) image.ExecConfig

ExecConfig returns the run configuration an image declares. A wasm artifact has none; its single module is the entrypoint.

func ParseBind added in v0.8.0

func ParseBind(b string) (container.Mount, error)

ParseBind reads "VOLUME:/path[:ro|:rw]".

Types

type CommitRequest added in v0.12.0

type CommitRequest struct {
	Container string
	// Repo and Tag name the image; with no Repo it stays addressable by ID
	// only (a <none> image).
	Repo, Tag string
	Comment   string
	Author    string
	// Config replaces the image config's "config" object (Docker's
	// semantics: the whole object); nil keeps the parent's, with the
	// container's command, environment, working directory and labels.
	Config *image.ExecConfig
	// Changes are Dockerfile instructions applied on top (commit -c).
	Changes []string
}

CommitRequest is POST /commit: a container's changes as a new image.

type CommitResult added in v0.12.0

type CommitResult struct {
	ID   image.Digest // the config digest
	Name string       // empty for a <none> image
}

CommitResult is what a commit made.

type CreateRequest

type CreateRequest struct {
	Name       string
	Image      string
	Entrypoint []string // nil = image's
	Cmd        []string // nil = image's
	Env        []string
	WorkingDir string
	Labels     map[string]string
	Memory     int64
	AutoRemove bool
	// Binds are "VOLUME:/path[:ro|:rw]": named volumes only (a host path
	// means nothing to a WebAssembly engine), created if missing.
	Binds []string
	// Network is the network to join by name or ID ("" or "default": the
	// engine's default; "none": no network).
	Network string
	// Caps are device capabilities granted to the container ("gpu").
	Caps []string
	// Restart is the restart policy (HostConfig.RestartPolicy).
	Restart container.RestartPolicy
	// Healthcheck overrides the image's health check field by field (an
	// empty Test, a zero duration or retry count: the image's).
	Healthcheck *container.HealthConfig
	// Endpoints are the networks' aliases by network (Docker's
	// NetworkingConfig.EndpointsConfig); a network named there and not in
	// Network is joined too (API 1.44+), and with no Network the first of
	// them by name is the primary.
	Endpoints map[string][]string
	// Ports are published ports (HostConfig.PortBindings, run -p);
	// ExposedPorts adds ports with no binding (Config.ExposedPorts, run
	// --expose), to the image's own; PublishAll gives each of those a port
	// the system picks (run -P).
	Ports        portmap.Map
	ExposedPorts map[string]struct{}
	PublishAll   bool
	// Tty, OpenStdin, StdinOnce and ConsoleSize ([height, width]): run -t
	// and -i (container/stdio.go).
	Tty, OpenStdin, StdinOnce bool
	ConsoleSize               [2]uint16
}

CreateRequest is a container create, with Docker's override rules: a set Entrypoint replaces the image's and drops its Cmd; a set Cmd replaces the image's Cmd; Env entries override the image's by key.

type Daemon

type Daemon struct {
	// contains filtered or unexported fields
}

Daemon is one engine instance.

func New

func New(opt Options) (*Daemon, error)

New opens the store under opt.Root.

func (*Daemon) Close

func (d *Daemon) Close(ctx context.Context) error

Close kills running containers.

func (*Daemon) Commit added in v0.12.0

func (d *Daemon) Commit(req CommitRequest) (CommitResult, error)

Commit writes a container's changes as a new image: the parent's layers, plus one layer with the container's changes (OCI whiteouts) when there are any, and a config whose history records the commit (an empty one marked empty_layer). The image is proved to unpack before it is named.

func (*Daemon) Containers

func (d *Daemon) Containers() *container.Manager

Containers is the container manager.

func (*Daemon) CreateContainer

func (d *Daemon) CreateContainer(req CreateRequest) (*container.Container, error)

CreateContainer makes a container from an image.

func (*Daemon) CreateVolume added in v0.8.0

func (d *Daemon) CreateVolume(name string, labels map[string]string) (*volume.Volume, error)

CreateVolume makes a volume (or returns the existing one).

func (*Daemon) DiskUsage added in v0.4.0

func (d *Daemon) DiskUsage() (DiskUsage, error)

DiskUsage measures images (each once, however many names it has), containers' writable layers, and the state store.

func (*Daemon) Events added in v0.6.0

func (d *Daemon) Events() *events.Bus

Events is the engine's event bus (GET /events).

func (*Daemon) Images

func (d *Daemon) Images() ([]ImageInfo, error)

Images lists images, one entry per image ID, newest first.

func (*Daemon) Load added in v0.12.0

func (d *Daemon) Load(ctx context.Context, r io.Reader, progress image.Progress) ([]Loaded, error)

Load stores every image of an OCI image layout sent as a tar (POST /images/load, what a builder exports): each index.json entry is pulled from the in-memory layout with every check a pull makes, proved to unpack, and named by its org.opencontainers.image.ref.name (a full image reference, or a tag of the layout's name). Nothing on the host is read.

func (*Daemon) NetworkConnect added in v0.14.0

func (d *Daemon) NetworkConnect(ctx context.Context, netRef, containerRef string, aliases []string) error

NetworkConnect puts a container on a network (network connect).

func (*Daemon) NetworkCreate added in v0.14.0

func (d *Daemon) NetworkCreate(name string, labels map[string]string) (network.Network, error)

NetworkCreate makes an in-engine network.

func (*Daemon) NetworkDisconnect added in v0.14.0

func (d *Daemon) NetworkDisconnect(netRef, containerRef string) error

NetworkDisconnect takes a container off a network (network disconnect).

func (*Daemon) NetworkPrune added in v0.14.0

func (d *Daemon) NetworkPrune(keep func(labels map[string]string) bool) []string

NetworkPrune removes the created networks no container uses whose labels keep accepts (nil: all), and returns their names.

func (*Daemon) NetworkRemove added in v0.10.0

func (d *Daemon) NetworkRemove(ref string) error

NetworkRemove removes a created network no container uses.

func (*Daemon) Networks added in v0.10.0

func (d *Daemon) Networks() *network.Manager

Networks is the network manager.

func (*Daemon) PruneImages added in v0.4.0

func (d *Daemon) PruneImages(all bool) ([]DeleteItem, int64, error)

PruneImages removes images no container uses; without all only dangling (unnamed) ones, which this store never keeps, so nothing.

func (*Daemon) PruneVolumes added in v0.8.0

func (d *Daemon) PruneVolumes(all bool) ([]string, int64)

PruneVolumes removes unused anonymous volumes, or with all every unused one.

func (*Daemon) Pull

func (d *Daemon) Pull(ctx context.Context, ref string, progress image.Progress) (string, *image.PullResult, error)

Pull fetches ref and names it; it returns the local name.

func (*Daemon) RemoveImage

func (d *Daemon) RemoveImage(ref string, force bool) ([]DeleteItem, error)

RemoveImage untags ref (or every name of an image given by ID) and deletes the image's blobs once no name is left. An image a container uses is refused unless force.

func (*Daemon) RemoveVolume added in v0.8.0

func (d *Daemon) RemoveVolume(name string, force bool) error

RemoveVolume deletes a volume no container uses; with force a missing one is not an error (Docker's meaning of force for volumes).

func (*Daemon) ResolveImage

func (d *Daemon) ResolveImage(ref string) (string, *image.Image, error)

ResolveImage finds an image by name ("hello", "hello:v1", "localhost:5000/x@sha256:…"), by ID ("sha256:…") or by unique ID prefix.

func (*Daemon) Restored added in v0.4.0

func (d *Daemon) Restored() container.RestoreReport

Restored says what was restored from the state store at start.

func (*Daemon) Storage added in v0.4.0

func (d *Daemon) Storage() StorageInfo

Storage describes the state store: what the embedder reports (Options.StorageInfo), plus the last failure to write to it.

func (*Daemon) TagImage added in v0.12.0

func (d *Daemon) TagImage(source, repo, tag string) (string, error)

TagImage gives the image source resolves to the name repo[:tag].

func (*Daemon) Volumes added in v0.8.0

func (d *Daemon) Volumes() *volume.Manager

Volumes is the volume manager.

type DeleteItem

type DeleteItem struct {
	Untagged string
	Deleted  string
}

DeleteItem is one line of an image removal.

type DiskUsage added in v0.4.0

type DiskUsage struct {
	LayersSize int64
	Images     []ImageInfo
	Containers []container.Snapshot
	Storage    StorageInfo
}

DiskUsage is what `system df` reports.

type ImageInfo

type ImageInfo struct {
	ID          image.Digest
	RepoTags    []string
	RepoDigests []string
	Created     time.Time
	Size        int64
	Labels      map[string]string
	Containers  int
	Image       *image.Image
}

ImageInfo is one image as `docker images` lists it.

type Loaded added in v0.12.0

type Loaded struct {
	Name string
	ID   image.Digest
}

Loaded is one image a load stored: its name (empty for an entry with no org.opencontainers.image.ref.name, kept as a <none> image) and ID.

type Options

type Options struct {
	// Root holds the image store on disk. One of Root and Backend is
	// required.
	Root string
	// Backend holds the image store elsewhere (memory, IndexedDB).
	Backend image.Backend
	// Limits bound pulls; zero means image.DefaultLimits.
	Limits image.Limits
	// Unpack bounds layer unpacking; zero means rootfs.DefaultLimits.
	Unpack rootfs.Limits
	// Registry configures registry pulls.
	Registry image.RegistryOptions
	// Containers configures the container manager (Executor required).
	Containers container.Options
	// MaxLowers bounds how many unpacked image trees stay in memory.
	MaxLowers int
	// StorageInfo, when set, reports the state store's usage for
	// `system df` (a browser's quota estimate, a disk's free space).
	StorageInfo func() StorageInfo
	// ImagesRemoved, when set, is called after images were deleted (the
	// browser executor drops its compiled-module cache then).
	ImagesRemoved func()
	// Volumes configures named volumes (they share Containers.Store).
	Volumes volume.Options
	// Networks configures networks (they share Containers.Store); every
	// engine has "bridge", its default, and "none".
	Networks network.Options
	// ModelSource opens the verified source of a registry model for the
	// read-only model mount (run --model NAME). Nil: the native cache
	// (models.CacheDir), where "wctr model pull" puts files. The browser
	// engine supplies the OPFS cache.
	ModelSource func(models.Entry) (models.Source, error)
}

Options configures a daemon.

type StorageInfo added in v0.4.0

type StorageInfo struct {
	Kind         string
	Usage, Quota int64 // bytes, -1 unknown
	Persistent   bool
	Error        string
}

StorageInfo is where the engine keeps its state and how full it is.

Jump to

Keyboard shortcuts

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