Getting started
Install untainer, build a micro-image from a Docker image and run it as a container in Node or in a browser tab.
untainer runs containers from OCI images (the images Docker runs) in a Linux VM compiled to WebAssembly. The same images run in Node and in a browser tab, with no Docker and no server: an image is a directory of static files, and only the parts a container reads are downloaded.
This page goes from nothing to a Node.js server running in a container, first in Node, then in a browser.
#Requirements
- Node 24 or newer, on macOS or Linux, for the CLI and to build images.
- A browser with WebAssembly JSPI, to run containers in a page: Chrome, Firefox and Safari have it in the versions tested (Chrome 158, Firefox on Linux, Safari 27).
- Images with a linux/arm64 variant. The official Docker Hub images have one.
#Install
pnpm add untainerThe package is both the library and the untainer command. The commands on this page are written
bare; with a local install, run them through your package manager (npx untainer build ...,
pnpm untainer build ...).
#1. Build an image
untainer build node:24-alpineThis downloads the image's linux/arm64 layers from Docker Hub, merges them into one read-only
file system in a VM, cuts it into chunks of 256 KiB and writes them, compressed, to
dist/node-24-alpine:
dist/node-24-alpine/
manifest.json how to run it: command, environment, user, ports
layers/<hash>.json the list of chunks
chunks/ one file per chunk, named by its hashThe layers are cached by digest, so the next build of the same image downloads nothing.
#2. Run it in Node
import { createRuntime, loadImage } from 'untainer';
const rt = await createRuntime({ images: [await loadImage('./dist/node-24-alpine')] });
const app = await rt.run('node:24-alpine', {
cmd: ['node', '-e', "require('http').createServer((q, s) => s.end('hello\\n')).listen(3000)"],
probe: 'http:3000/',
});
await app.ready();
const res = await app.fetch('/', { port: 3000 });
console.log(await res.text()); // hello
await rt.shutdown();createRuntime() boots one VM; rt.run() starts a container in it and resolves once its process
runs; ready() waits for the probe. app.fetch() reaches the container's port inside the VM.
The VM has no incoming connections from the outside, so ports are not published on your machine.
Or from the command line, which streams the container's output and stops it on Ctrl-C:
untainer run dist/node-24-alpine -- node -e "console.log(process.version)"#3. Run it in a browser
Serve the image directory next to your page: copy it to where your site's static files are, or
run untainer serve dist while you try it. Then:
import { createRuntime, loadImage } from 'untainer';
const rt = await createRuntime({ worker: true, memoryMiB: 256 });
const image = await loadImage('/images/node-24-alpine/');
const app = await rt.run(image, {
cmd: ['node', '-e', "require('http').createServer((q, s) => s.end('hi')).listen(3000)"],
probe: 'http:3000/',
});
await app.ready();
console.log(await (await app.fetch('/', { port: 3000 })).text()); // hiworker: true(the default, written out) runs the VM in a Web Worker, so the page stays responsive.- Chunks are fetched as the container reads them, checked against their hash, and kept in the
browser's storage (OPFS, else IndexedDB): a second start downloads only
manifest.json. - No special headers are needed. A page that sends COOP and COEP lets the VM share memory with the page; that matters only for more than one CPU.
examples/browser in the repository is this page as a static site, ready to deploy.
#4. Or load an image from GitHub
A built image pushed to a repository runs by reference, in Node and in the browser:
import { createRuntime } from 'untainer';
const rt = await createRuntime({
images: ['gh:OskarLebuda/untainer-images/hello#hello-78fc67baa844'],
});
const web = await rt.run('hello');
await web.ready();
console.log(await (await web.fetch('/')).text()); // hello from untainer
await rt.shutdown();gh: reads raw.githubusercontent.com; jsdelivr: and npm: read jsDelivr's CDN. Pin a tag or a
commit: a branch can change under a running application.
#Where next
- Postgres in the browser: a real database in a tab, with data that stays.
- A VM in Vitest tests: services for tests, without Docker.
- Hosting images on GitHub: publish an image and load it by reference.
- Concepts: how images, chunks, the runtime and memory work, and what they cost.
- Limits: what untainer does not do.