Getting started
Cairn turns an OCI image (what Docker and podman run) into a Firecracker microVM on your own Linux host. You run it as an ordinary user, and each VM runs inside a jail. This page takes you from a fresh host to a running nginx that you can curl, then shows the everyday commands.
What you get
- A real virtual machine per app, with its own kernel, not a shared-kernel container.
- No daemon you have to run and no root shell for daily use. A few small helper programs are installed with elevated rights once, by the package. See security.
- Deploys that wait for the app to be ready, and start the previous release again if it never is.
- Apps that restart on failure and can start at boot.
If you only know containers: an image is the filesystem and start command, and cairn boots it as a VM. The image's ENTRYPOINT and CMD become the one process the VM runs. See concepts for the vocabulary.
Requirements
- Linux on x86_64, kernel 6.17 or later, with KVM (
/dev/kvm) and/dev/net/tun. - Either Fedora/RHEL (rpm) or Debian/Ubuntu (deb), to install the package.
nft(nftables), whichcairn doctorchecks for.- To build an image from a Dockerfile: rootless podman or docker. If you only pull a published image (
image = "..."), you do not need one.
cairn doctor checks all of this and tells you the fix for each failure.
Install
Build and package from the source tree, as yourself:
make build
make installmake install builds and validates the package for this host and prints the one command that installs exactly that file, for example sudo dnf install <archive>. It never runs sudo itself. Run the printed command with your own root access.
Then allow your user:
sudo usermod -aG cairn <user>The package creates the cairn group. Membership takes effect at once; cairn reads /etc/group on every call, so you need no new login.
On Ubuntu also run sudo usermod -aG kvm <user> (there /dev/kvm is root:kvm 0660; on Fedora it is world-writable). That one does need a new login. If you already have linger on (loginctl show-user <user> -p Linger says yes), your user manager kept its old groups, so also run sudo systemctl restart user@<uid>.service. That stops every user service and VM of that user.
On Ubuntu 24.04 and later the deb installs and loads the AppArmor profiles /etc/apparmor.d/cairn and /etc/apparmor.d/cairn-netd (unconfined apart from userns, for the packaged programs only). That is why kernel.apparmor_restrict_unprivileged_userns=1 can stay set: cairn-netd makes a user namespace per network, and cairn runs its root-disk build inside one. The postinst warns if loading the profiles fails, and cairn doctor checks that they are loaded and names the apparmor_parser command if they are not. Do not set the sysctl to 0 for cairn.
Stock Fedora Cloud images have / at mode 775, and the jail refuses to run below a directory others can write. cairn doctor fails with a row ending sudo chmod go-w /. Run it once.
See development for building packages for CI and troubleshooting if a step fails.
Check access and the host
cairn accesswork (uid 1001)
work member
allowed: work is in the cairn group's member listcairn access --check prints the same and exits 1 when you may not use cairn, for scripts.
cairn doctorOn a terminal doctor shows one summary line per area and then each warning or failure with its fix. Add -v to see every check. Piped, you always get every check. Example (abridged, real output from a healthy host):
[ok ] the cairn group exists (gid 964)
[ok ] you may use cairn (in the member list as work)
[ok ] this shell can open /dev/kvm
[ok ] your user manager can open /dev/kvm
[ok ] cairn-helper answers status, and its access answer agrees
[ok ] kernel 7.2.14-100.fc43.x86_64 is 6.17 or later
[ok ] builder: podman (podman version 5.8.9)
[warn] network ubuntu: no app owns or uses it, and it holds one of your network slots
fix: cairn net destroy ubuntu, if nothing needs it[warn] rows are worth reading but do not block a deploy. [fail] rows must be fixed first. Doctor must be clean for both this shell and your user manager: the rows "this shell can open" and "your user manager can open" are separate on purpose, because the supervisor of a machine started at boot runs under the user manager.
Start at boot (optional)
VMs start at boot through your systemd user manager, which exists at boot only with linger on:
loginctl enable-linger <user>
cairn doctorWithout systemd, everything else works but nothing starts at boot, and the cleanup timers are replaced by /etc/cron.d/cairn when cron is installed.
The guest kernel
Cairn boots a pinned kernel, 6.1.155. You do nothing: the first deploy downloads it, checks its sha256 and saves it read-only under ~/.cairn/kernels/. To fetch it ahead of time, or offline:
cairn kernel fetch
cairn kernel install <file> # a kernel file you already haveProjects can supply their own kernel. See kernels.
Deploy nginx
Make a directory with one file, cairn.toml:
version = 1
app = "web"
image = "docker.io/library/nginx:1.27"
[[services]]
internal_port = 80
[[services.ports]]
port = 8080internal_port is the port inside the VM. port is the port on your host. It is published on 127.0.0.1 unless you set bind. The full file is in manifest.
Preview what cairn will do, without changing anything:
cairn deploy --dry-rundry run: nothing was changed
app web
project /home/you/web
image docker.io/library/nginx:1.27 (pulled only when absent; --pull always pulls)
builder podman, else docker
machine 1 vCPU, 512mb (512 MiB) memory, 2gb (2048 MiB) root filesystem (thin), kernel 6.1.155
balloon on: memory the guest frees goes back to the host (best effort: page cache and free blocks under 128 KiB stay)
jail require
process the image's ENTRYPOINT + CMD
env (none)
network nat on `web`, dns host
restart on-failure
a VMM failure is always recovered
ready TCP port 80 must accept before the machine is accepted (automatic)
publish tcp 127.0.0.1:8080 -> guest port 80
paths
kernel ~/.cairn/kernels/vmlinux-6.1.155 (read-only at /vmlinux in the jail)
build scratch ~/.cairn/build
machine dir ~/.cairn/apps/web/machines/<id> (/vm in the jail)
root disk ~/.cairn/apps/web/machines/<id>/rootfs.ext4
config disk ~/.cairn/apps/web/machines/<id>/config.ext4
vm.json ~/.cairn/apps/web/machines/<id>/vm.json
console log ~/.cairn/apps/web/machines/<id>/console.log
firecracker log ~/.cairn/apps/web/machines/<id>/firecracker.logThen deploy:
cairn deployReal output (on a terminal the progress lines are redrawn in place):
getting the image
image 1e5f3c5b981a (docker.io/library/nginx@sha256:6784fb08…), cached (not pulled; --pull fetches the registry's current tag)
building the root disk
starting the machine
waiting TCP service port 80 (automatic); limit 60s
waiting port 80: waiting to accept (59s left)
ready port 80 accept, 1.0s after the workload started; accepted
publishing tcp://127.0.0.1:8080
start at boot: enabled cairn-machine-web-YJ449SSML5.service
app web
machine YJ449SSML5
directory ~/.cairn/apps/web/machines/YJ449SSML5
image image 1e5f3c5b981a (docker.io/library/nginx@sha256:6784fb08…), cached
network web (created for this deploy)
endpoint tcp://127.0.0.1:8080
root disk 2.0 GiB, 201.1 MiB allocated
built in 1.7 s
console ~/.cairn/apps/web/machines/YJ449SSML5/console.log
vmm log ~/.cairn/apps/web/machines/YJ449SSML5/firecracker.log
launcher systemd
stop with SIGQUIT (the image)
at boot starts at boot: yes
ready: TCP port 80 accepted connections before it was accepted
health: not monitored; add [checks.web] http = "/healthz" to define application health
if it fails, the machine is booted again (backoff 1 s, doubling to 60 s); run cairn status webThe first deploy of an image takes longer, because the image is pulled; this run had it cached and took 4 seconds. Cairn does not accept the new machine until port 80 accepts connections, and a deploy that never becomes ready rolls back and starts the previous release again. Use --wait-timeout to change the 60 second deadline. A redeploy stops the old machine before it starts the new one, so the app does not answer for a moment; and the new machine serves as soon as it listens, before it is accepted.
If a deploy is killed part-way (a crash, a second Ctrl+C, a power loss), it stays recorded in ~/.cairn/apps/web/deploy.json, and cairn status web says so. The next cairn deploy, cairn start web, cairn stop web or cairn destroy web settles it: it deletes the new machine or rolls back to the old one. Settling never starts anything, so if the old machine had already been stopped the app stays down until you run cairn start web or deploy again. After a power loss while the new machine was starting, that includes the reboot: run cairn start web after it (it does nothing if the app is already running).
curl -i http://127.0.0.1:8080/The answer is nginx's welcome page.
Look at it
cairn ps # every app and VM you own: state, health, restarts, endpoints
cairn ps --apps # one row per app
cairn status web # one app in detail: state, kernel, disks, log paths, last console linesAPP ROLE STATE HEALTH TIME RESTARTS ENDPOINTS MACHINE
web current running - up 5s 0 tcp://127.0.0.1:8080 YJ449SSML5app web
state running
machine YJ449SSML5
uptime 5s
network web
image sha256:1e5f3c5b981a9f91ca91cf13ce87c2eedfc7a083f4f279552084dd08fc477512
kernel 6.1.155 (pin)
root disk 2.0 GiB, 201.1 MiB allocated
endpoint tcp://127.0.0.1:8080
console ~/.cairn/apps/web/machines/YJ449SSML5/console.log
vmm log ~/.cairn/apps/web/machines/YJ449SSML5/firecracker.log
launcher systemd, run 1
unit cairn-machine-web-YJ449SSML5.service (also cairn-app-web.service)
at boot yes
pids supervisor 984177, VMM 984180, workload 272 (in the guest)
events open
health - (no health checks configured; add [checks.<name>] to define application health)
restart on-failure
heartbeat armed
log size 19.4 KiB on disk
endpoints are the last confirmed configuration, not a reachability checkcairn status prints the paths of the machine's console.log (what the guest wrote to its serial console, including your app's output) and firecracker.log. Read them with tail. See troubleshooting.
To run a command or get a shell inside the VM:
cairn exec web -- nginx -v
cairn console webBoth are covered in lifecycle.
Stop, start and destroy
cairn stop web # shuts the machine down; keeps its disk and network
cairn start web # boots it again on the same disk
cairn destroy web # deletes the app and its machines (not its volumes, not the network)$ cairn stop web
machine YJ449SSML5 stopped
`cairn start web` boots it again with its disk as it is
the stopped app still holds tcp://127.0.0.1:8080; `cairn start web` brings it back, `cairn destroy web` releases them
$ cairn start web
machine YJ449SSML5 started (pid 984502; supervised by 984492; launcher systemd)
starts at boot: yes
endpoint tcp://127.0.0.1:8080
$ cairn destroy web
machine YJ449SSML5 stopped
unpublished tcp://127.0.0.1:8080
detached YJ449SSML5
removed machine directory YJ449SSML5
app web destroyed; its network was left in placestopsends the workload a graceful signal, waits (20 seconds by default, or the app'skill_timeoutplus 10), then kills the VM.--timeoutchanges the wait.destroykeeps persistent volumes and lists them. Add--volumesto delete their data too. See volumes.destroyleaves the app's network defined.cairn net destroy <name>removes it. See networking.cairn pause webfreezes the VM in memory andcairn resume webthaws it. Both go through the machine's supervisor, which records the pause, socairn statusshowspaused.
Removing users and cairn
Remove a user. cairn access <user> lists every name for the uid and which are members. Run sudo gpasswd -d <name> cairn for each name marked member, then run cairn access <user> again: it must say not allowed and list no padded entry. A padded entry is removed with sudo vigr; gpasswd -d cannot remove it, and a successful gpasswd -d does not prove revocation, so the second check is mandatory. Their running VMs keep running: the user (or root with sudo -iu <user>) stops them as below, or runs cairn destroy. A stopped cairn run app keeps its unsynced files on its disk: re-add the user for the recovery, then remove them again.
Stop everything and keep the data. As each user:
cairn ps # see what is running
cairn stop <app> # for each running app; its disk is kept
cairn run --stop # instead, in the folder of a running cairn run app
cairn ps # every app shows stopped
systemctl --user stop cairn-net-<network>.service # for each network (cairn net ls); it is keptAfter reinstalling, cairn net up <network> and cairn start <app> bring them back. To delete instead, which cannot be undone: cairn destroy <app> and cairn net destroy <network>.
Remove the package. Stop everything first, then sudo dnf remove cairn or sudo apt remove cairn. Removal keeps every app's disks and network definitions. If anything is still running, removal refuses and prints the list; /var/lib/cairn/force-remove is the explicit escape hatch. On Fedora prefer sudo dnf --setopt=clean_requirements_on_remove=False remove cairn: dnf removes now-unneeded weak dependencies (Git, for example) before the package's own removal script can refuse, so a refusal does not by itself prove the whole transaction changed nothing.
Next
- Change CPU, memory, environment, health checks: manifest.
- How deploys, restarts and health work: lifecycle.
- Persistent data: volumes. Reaching the network: networking.
- Running an AI agent against a local folder: run.
- Something broke: troubleshooting.