Skip to main content
Inspect and prune the local OCI image cache: the images that sandbox creation has already pulled. Images can also be loaded into the cache from local archives and saved back out to archive files, so locally built images work without a registry. Everything is reached through the package-level Image value, or through an ImageHandle once you hold one.

Functions

Image.Get()

Fetch one cached image by reference. Returns ErrImageNotFound when no image with that reference is present in the local cache.

Parameters

ctxcontext.Context
Cancels the lookup.
referencestring
Image reference, e.g. “python:3.12”.

Returns

Metadata handle for the cached image.
error
ErrImageNotFound when the reference is not cached.

Image.List()

Return every cached image, ordered by creation time (newest first).

Parameters

ctxcontext.Context
Cancels the listing.

Returns

All cached image handles, newest first.
error
Non-nil on failure.

Image.Inspect()

Return the full detail for a cached image: the ImageHandle plus the parsed OCI config and the layer list.

Parameters

ctxcontext.Context
Cancels the inspection.
referencestring
Image reference, e.g. “python:3.12”.

Returns

Handle, OCI config, and layers.
error
ErrImageNotFound when the reference is not cached.

Image.Remove()

Delete a cached image. When force is false, sandboxes that still reference the image cause the call to fail with ErrImageInUse.

Parameters

ctxcontext.Context
Cancels the removal.
referencestring
Image reference to delete.
forcebool
When true, remove even if sandboxes still reference it.

Returns

error
ErrImageInUse when in use and force is false.

Image.Prune()

Remove cached image data that is not used by any sandbox or indexed snapshot. Returns a report tallying the image refs, manifests, layers, fsmeta files, and VMDK files removed, plus bytes reclaimed.

Parameters

ctxcontext.Context
Cancels the prune.

Returns

Summary of what was reclaimed.
error
Non-nil on failure.

Image.Load()

function
Import images from a local archive (a docker save tarball or an OCI Image Layout archive) into the cache, so locally built images can be used without a registry. Variadic tags apply extra references to the first image in the archive.

Parameters

ctxcontext.Context
Cancels the import.
inputPathstring
Path to the archive file.
tags…string
Extra references applied to the first image in the archive.

Returns

One handle for every image reference imported.
error
Non-nil on failure.

Image.Save()

function
Export one or more cached images to an archive file at outputPath. ImageArchiveDocker (the default; "" behaves the same) writes an archive loadable with docker load; ImageArchiveOCI writes an OCI Image Layout archive. Returns ErrImageNotFound when any reference is missing from the local cache.

Parameters

ctxcontext.Context
Cancels the export.
references[]string
Image references to export, e.g. “python:3.12”.
outputPathstring
Path of the archive file to write.
ImageArchiveDocker (default; "" behaves the same) or ImageArchiveOCI.

Returns

error
ErrImageNotFound when any reference is not cached.

Methods

Instance methods on *ImageHandle, the metadata reference returned by Image.Get and Image.List. The accessors are pure reads of cached metadata; only Remove and Inspect take a context and reach the runtime.

h.Reference()

The image reference, e.g. "docker.io/library/python:3.12".

Returns

string
Image reference.

h.ManifestDigest()

The content-addressable manifest digest, or empty when unknown.

Returns

string
Manifest digest, or empty.

h.Architecture()

The architecture resolved during the pull, or empty.

Returns

string
Architecture, or empty.

h.OS()

The operating system resolved during the pull, or empty.

Returns

string
Operating system, or empty.

h.LayerCount()

The number of layers in the image.

Returns

uint
Layer count.

h.SizeBytes()

The total image size in bytes, or nil when unknown.

Returns

*int64
Total size in bytes, or nil.

h.CreatedAt()

When this image was first pulled. Returns the zero time.Time when unknown.

Returns

time.Time
First-pulled time, or the zero value.

h.LastUsedAt()

When this image was last referenced. Returns the zero time.Time when unknown.

Returns

time.Time
Last-referenced time, or the zero value.

h.Remove()

Delete this image. Equivalent to Image.Remove(ctx, h.Reference(), force). When force is false, sandboxes that still reference the image cause the call to fail with ErrImageInUse.

Parameters

ctxcontext.Context
Cancels the removal.
forcebool
When true, remove even if sandboxes still reference it.

Returns

error
ErrImageInUse when in use and force is false.

h.Inspect()

Return the full detail for this image. Equivalent to Image.Inspect(ctx, h.Reference()).

Parameters

ctxcontext.Context
Cancels the inspection.

Returns

Handle, OCI config, and layers.
error
Non-nil on failure.

Types

ImageHandle

Returned by Image.Get() · Image.List()

A lightweight metadata reference to a cached OCI image. Fields are unexported; read them through the accessor methods below. Embedded in ImageDetail.

ImageDetail

Returned by Image.Inspect() · Inspect()

Bundles an ImageHandle (embedded, so all its accessors are promoted) with the parsed OCI config and layer list.

ImageConfig

Used by ImageDetail.Config

The parsed OCI config block.

ImageLayer

Used by ImageDetail.Layers

One layer of an image manifest.

ImagePruneReport

Returned by Image.Prune()

Summarizes the artifacts removed by Image.Prune.

ImageArchiveFormat

type

Used by Image.Save()

Selects the archive layout written by Image.Save.