Images¶
The daemon holds the images sandboxes start from: those of the kits, and the
templates saved from sandboxes. client.images lists,
pulls, reads, moves and removes them. This page covers each of those.
docs_src/client/images.py
import fastsandbox
async def main() -> None:
client = await fastsandbox.connect()
images = client.images
for image in await images.list():
print(f"{image.reference} {image.size or 0} bytes")
# A pull followed as it happens; `images.pull()` waits for its end instead.
reference = "docker.io/sbx/shell:latest"
async with await images.pull_stream(reference) as progress:
async for line in progress:
if line.error is not None:
raise RuntimeError(f"pull failed: {line.error}")
print(f"pull: {line.status}")
details = await images.inspect(reference)
print(f"{reference}: user {details.user}, entrypoint {details.entrypoint}")
print(f"unknown image held: {await images.exists('docker.io/library/no-such:image')}")
if __name__ == "__main__":
fastsandbox.run(main())
Listing and reading¶
| Call | Gives |
|---|---|
list() |
every image, untagged ones included, as ImageSummary; reference names it |
exists(reference) |
whether the daemon holds it |
inspect(reference) |
its details, an ImageInspect: user, entrypoint, command, agent; NotFoundError for an image the daemon does not hold |
local_metadata(reference) |
whether it is a locally saved snapshot; an unknown image gives the defaults, not an error |
Pulling¶
pull(reference)pulls an image and waits for the outcome. A pull the registry refuses raises anApiError, such as403 registry_access_denied; a failure reported during the pull, anOperationFailedError. When the registry refuses a pull, a cached copy is used, as the CLI does.pull_stream(reference)pulls it and streams its progress, aPullProgressper line: astatus, the layerid, the byte counts ofprogress_detail, and anerror, always the last line of a failed pull. Layers report the same status many times.
Pulls are long operations: their deadline is the long-operation deadline of the client (see Deadlines). The images of a kit are loaded from its package when a sandbox is created; forging the package pulls the image of its base kit, once (see Kits).
Moving images¶
An image moves between daemons as an archive, in the docker save format:
export(reference)gives the archive as bytes (NotFoundErrorfor an unknown image), held in memory whole, andexport_stream(reference)by chunks, as the daemon sends them, for an archive of hundreds of megabytes that a program writes to a file as it comes;load(archive)loads one from bytes, andload_file(path)from a file of the host;remove(reference)removes an image.
A template saved from a sandbox (see Templates) goes to another host this way: