
# CLI

::note
Written by `node site/scripts/reference.ts` from the CLI's own help (`untainer <command>
--help`); do not edit it by hand.
::

## untainer

untainer - Containers on unkernel

```sh
untainer <COMMAND> [OPTIONS]
```

OCI images as lazily loaded micro-images, run as containers in an unkernel VM. No Docker, no server: a micro-image is a directory of static files any CDN can serve.

| Command | |
| --- | --- |
| `build` | Build a micro-image from an OCI image in a registry |
| `base` | Build a base image that other images are built over |
| `run` | Run an image directory or a reference in a container |
| `up` | Start the services of a compose file, each in its container |
| `ps` | List the containers run in the background (run -d) |
| `logs` | Print the output of a container run in the background |
| `stop` | Stop containers run in the background |
| `inspect` | Show the layers, sizes and configuration of an image |
| `images` | List the images and the rest of the cache directory |
| `prune` | Remove unused images, layers and chunks from the cache directory |
| `serve` | Serve images and pages over HTTP, with the headers untainer needs |
| `bench` | Measure a cold and a warm start of an image |

| Option | |
| --- | --- |
| `-h, --help` | Print help |

```sh
untainer build postgres:17-alpine
untainer run dist/postgres-17-alpine -e POSTGRES_PASSWORD=dev
untainer run node:24-alpine -u node -- node -e "console.log(1)"
```

Documentation: https://untainer.dev

## untainer build

Build a micro-image from an OCI image in a registry

```sh
untainer build <REF> [OPTIONS] [-- <COMMAND>...]
```

Takes the linux/arm64 variant of REF, merges its layers into one erofs image in an unkernel VM (no distro image, no network in the guest) and writes manifest.json, layers/ and chunks/ to DIR. Layers are cached by digest in ~/.cache/untainer, so the next build of the image downloads nothing.

| Argument | |
| --- | --- |
| `<REF>` | Image reference: postgres:17-alpine, ghcr.io/org/app:v1, app@sha256:... |
| `<COMMAND>...` | With --probe: the command of the profiling start (not recorded) |

| Option | |
| --- | --- |
| `-o, --out <DIR>` | Output directory (default: dist/<name>-<tag>) |
| `--chunk-size <SIZE>` | Bytes per chunk, or with k or m (default: 256k) |
| `--zstd-level <N>` | zstd level 1-22 (default: 3; 19: ~14% smaller, far slower, for publishing) |
| `--probe <PROBE>` | Readiness probe to record: tcp:<port>, http:<port><path>, exec:<command> |
| `--memory <MiB>` | Guest memory the image needs, to record (default with --probe: measured) |
| `-e, --env <KEY=VALUE>` | Environment for that measuring start (repeatable; not recorded) |
| `--profile-script <SH>` | With --probe, a script run in the container once ready, as load: its reads and memory count (not recorded) |
| `--no-profile` | With --probe, do not start the image (no memory, no boot bundle) |
| `--no-layout` | With --probe, keep the flat layout instead of laying it out by the start |
| `--profile <FILE>` | Take the starts' results from an earlier build's profile.json: the same image, no start |
| `--boot-part-size <SIZE>` | Largest boot bundle part, or with k or m; 0: none (default: 4m) |
| `--base <DIR>` | Base image to build over when the layers start with its (repeatable; default: those of untainer base) |
| `--no-base` | Build no base layer, even when one matches |
| `--slim[=files\|chunks]` | With --probe, remove files its start does not touch, then start it again; =chunks: also the unread parts of files it touched (the image then does only what the probe did) |
| `--keep <PATH>` | With --slim, keep this file or directory whole (repeatable) |
| `--no-trace` | With --slim, keep only what --keep names, not what the start reads |
| `--mirror <URL>` | Docker Hub mirror for when Docker Hub answers 429 (repeatable) |
| `--json` | Print the result as JSON |
| `-h, --help` | Print help |

```sh
untainer build node:24-alpine
untainer build ghcr.io/org/app:v1 -o ./app --probe http:8080/health
untainer build postgres:17-alpine --probe tcp:5432 -e POSTGRES_PASSWORD=dev
untainer build postgres:17-alpine --chunk-size 128k --json
untainer build ghcr.io/org/app:v1 -o ./publish/app --zstd-level 19
```

## untainer base

Build a base image that other images are built over

```sh
untainer base <REF> [OPTIONS]
```

Builds REF like untainer build, as one layer marked as a base, laid out and bundled by a start of its shell. Later builds of images whose layers start with REF's use it as their bottom layer and keep only what they add: images over the same base share its chunks.

| Argument | |
| --- | --- |
| `<REF>` | Image reference: alpine:3.24, debian:bookworm-slim |

| Option | |
| --- | --- |
| `-o, --out <DIR>` | Output directory (default: ~/.cache/untainer/bases/<name>-<tag>) |
| `--mirror <URL>` | Docker Hub mirror for when Docker Hub answers 429 (repeatable) |
| `-h, --help` | Print help |

```sh
untainer base alpine:3.24
untainer build node:24-alpine --probe http:3000/
```

## untainer run

Run an image directory or a reference in a container

```sh
untainer run <IMAGE> [OPTIONS] [-- <COMMAND>...]
```

Streams the container's output until it exits; Ctrl-C stops it. untainer exits with the container's exit code. Its own messages go to stderr, so the container's stdout can be piped.

| Argument | |
| --- | --- |
| `<IMAGE>` | Image directory, gh:/npm:/https:// micro-image, or an OCI reference (built first) |
| `<COMMAND>...` | Replaces the image's command |

| Option | |
| --- | --- |
| `-e, --env <KEY=VALUE>` | Add to the environment (repeatable) |
| `-p, --publish <HOST:CONTAINER>` | Publish a container port on 127.0.0.1 (repeatable) |
| `-v, --volume <HOST:CONTAINER[:ro]>` | Mount a host directory, owned by the container user (repeatable) |
| `--tmpfs <CONTAINER[:MiB]>` | Mount an empty tmpfs, owned by the container user (repeatable) |
| `--name <NAME>` | Container name |
| `-u, --user <USER>` | user, uid, user:group or uid:gid (default: the image's) |
| `-w, --workdir <DIR>` | Working directory (default: the image's) |
| `--no-init` | Run the command itself as PID 1, without untainer's init |
| `--memory <MiB>` | Guest memory (default: the image's profile.memoryMiB, else 1024) |
| `--net[=all]` | Give the guest the internet, but not this host, its local network or link-local (=all: all) |
| `-d, --detach` | Run in the background, in a VM of its own; print the name (default: the image name) |
| `-h, --help` | Print help |

```sh
untainer run dist/postgres-17-alpine -e POSTGRES_PASSWORD=dev
untainer run -d -p 5432:5432 dist/postgres-17-alpine -e POSTGRES_PASSWORD=dev
untainer run node:24-alpine -u node -- node -e "console.log(process.version)"
untainer run gh:user/images/postgres-17#v1 -e POSTGRES_PASSWORD=dev
```

Without --net the guest has no network. --net checks each connection on the address it goes
to and refuses loopback, this host's own addresses, 10/8, 172.16/12, 192.168/16, 100.64/10,
169.254/16 (cloud metadata), multicast, reserved ranges and the IPv6 equivalents.

## untainer up

Start the services of a compose file, each in its container

```sh
untainer up [OPTIONS]
```

Reads image, environment, ports, volumes, depends_on and command of each service, and warns about the keys it ignores. A service starts once the ones it depends on are ready (their probes passed); the others reach it by its name. All share one VM. Each service's output follows, prefixed with its name; Ctrl-C stops them all.

| Option | |
| --- | --- |
| `-f, --file <FILE>` | Compose file (default: compose.yaml, compose.yml, docker-compose.yaml) |
| `-p, --project-name <NAME>` | The project's name, for its named volumes (default: name:, else the directory) |
| `--memory <MiB>` | Guest memory (default: the sum of the images' profile.memoryMiB) |
| `--net[=all]` | Give the guests the internet, but not this host, its local network or link-local (=all: all) |
| `-h, --help` | Print help |

```sh
untainer up
untainer up -f examples/compose/compose.yaml
```

An image is an image directory (relative to the file), a gh:/npm:/https:// micro-image, or an
OCI reference (built first). A named volume is a directory in ~/.cache/untainer/volumes.

## untainer ps

List the containers run in the background (run -d)

```sh
untainer ps [OPTIONS]
```

Each runs in a background untainer process with a VM of its own; its state file and output are in ~/.cache/untainer/containers. A container whose process died without saying how it ended (SIGKILL, a restart) shows as gone.

| Option | |
| --- | --- |
| `-a, --all` | Also the containers that exited |
| `--json` | Print the state files as JSON |
| `-h, --help` | Print help |

## untainer logs

Print the output of a container run in the background

```sh
untainer logs <NAME> [OPTIONS]
```

Its stdout and stderr in one, and untainer's own lines (the start, errors).

| Argument | |
| --- | --- |
| `<NAME>` | The container, as untainer ps lists it |

| Option | |
| --- | --- |
| `-f, --follow` | Go on printing what it writes until it exits |
| `-h, --help` | Print help |

## untainer stop

Stop containers run in the background

```sh
untainer stop <NAME>...
```

Sends SIGTERM to each container, as Ctrl-C does for untainer run (SIGKILL after 10 s), and waits until its VM is gone. Its state and output stay for untainer ps -a and untainer logs.

| Argument | |
| --- | --- |
| `<NAME>...` | The containers, as untainer ps lists them |

| Option | |
| --- | --- |
| `-h, --help` | Print help |

## untainer inspect

Show the layers, sizes and configuration of an image

```sh
untainer inspect <DIR> [OPTIONS]
```

| Argument | |
| --- | --- |
| `<DIR>` | Image directory |

| Option | |
| --- | --- |
| `--json` | Print the manifest and the layer sizes as JSON |
| `-h, --help` | Print help |

```sh
untainer inspect dist/postgres-17-alpine
```

## untainer images

List the images and the rest of the cache directory

```sh
untainer images [OPTIONS]
```

Lists the images in the cache directory (built by untainer run <reference>) with their size on disk and when they were written, then what else the cache holds. There is no daemon: this reads the files.

| Option | |
| --- | --- |
| `--json` | Print the list as JSON |
| `-h, --help` | Print help |

```sh
untainer images
untainer images --json
```

## untainer prune

Remove unused images, layers and chunks from the cache directory

```sh
untainer prune [OPTIONS]
```

Removes what is unused or can be made again without the network: directories that hold no valid image, decompressed layer tars, downloads older than an hour, and chunks no stored layer index lists. --all also removes what can be downloaded or built again: OCI layers, built images, the chunk store, toolbox packages.

| Option | |
| --- | --- |
| `--dry-run` | Show what would be removed, remove nothing |
| `--all` | Also remove everything that can be downloaded or built again |
| `-h, --help` | Print help |

```sh
untainer prune --dry-run
untainer prune --all
```

## untainer serve

Serve images and pages over HTTP, with the headers untainer needs

```sh
untainer serve [DIR] [OPTIONS]
```

Serves DIR (default: the current directory) with CORS for other origins, immutable caching for chunks and layer indexes, and byte ranges. Without COOP and COEP by default, as most static hosts serve; --isolate adds them (shared memory between the page and the VM, more CPUs).

| Argument | |
| --- | --- |
| `[DIR]` | Directory to serve (default: .) |

| Option | |
| --- | --- |
| `-p, --port <PORT>` | Port (default: 8080; 0 for any free one) |
| `--host <HOST>` | Address to listen on (default: 127.0.0.1) |
| `--isolate` | Send COOP and COEP, so its pages are cross-origin isolated |
| `-h, --help` | Print help |

```sh
untainer serve dist
untainer serve examples/browser/dist --port 3000 --isolate
```

## untainer bench

Measure a cold and a warm start of an image

```sh
untainer bench <IMAGE> [OPTIONS] [-- <COMMAND>...]
```

Starts IMAGE until its probe passes, twice: cold (an empty chunk store and cache) and warm (the store the cold start filled, a new cache). Prints the time to ready and where the chunks came from: the source (the network for a URL), the store, the cache.

| Argument | |
| --- | --- |
| `<IMAGE>` | Image directory, URL or reference (gh:, npm:, ...) |
| `<COMMAND>...` | Replaces the image's command |

| Option | |
| --- | --- |
| `-e, --env <KEY=VALUE>` | Add to the environment (repeatable) |
| `--probe <PROBE>` | Readiness probe (default: the image's, else TCP on its first port) |
| `--memory <MiB>` | Guest memory (default: the image's profile.memoryMiB, else 1024) |
| `--runs <N>` | Warm starts after the cold one (default: 1) |
| `--json` | Print the result as JSON |
| `-h, --help` | Print help |

```sh
untainer bench dist/node-24-alpine --probe http:3000/ -- node -e "require('http').createServer((q, s) => s.end()).listen(3000)"
untainer bench https://cdn.example/postgres-17/ -e POSTGRES_PASSWORD=dev
```
