Skip to content

Quickstart ​

This page deploys nginx in a microVM, opens it in your browser, and shows the everyday commands. It assumes you have installed cairn and cairn doctor shows no failures.

Step 1: describe the app ​

Make an empty directory and put one file in it, cairn.toml:

toml
app = "web"
image = "docker.io/library/nginx:1.27"

[[services]]
internal_port = 80          # the port nginx listens on inside the VM

  [[services.ports]]
  port = 8080               # the port on your computer
  • app is the name you will use in every other command.
  • image is any image you could docker pull or podman pull.
  • [[services]] says which port your app serves. The [[services.ports]] entry publishes it on your computer. By default it is published on 127.0.0.1, so only this computer can reach it.

Every other setting has a sensible default. See cairn.toml for the full list.

Step 2: preview (optional) ​

sh
cairn deploy --dry-run

This shows everything cairn is about to do, with each default filled in, and changes nothing:

text
dry run: nothing was changed

app         web
image       docker.io/library/nginx:1.27 (pulled only when absent; --pull always pulls)
machine     1 vCPU, 512mb (512 MiB) memory, 2gb (2048 MiB) root filesystem (thin), kernel 6.1.155
network     nat on `web`, dns host
restart     on-failure
ready       TCP port 80 must accept before the machine is accepted (automatic)
publish     tcp 127.0.0.1:8080 -> guest port 80
...

Step 3: deploy ​

sh
cairn deploy
text
getting the image
building the root disk
starting the machine
waiting   TCP service port 80 (automatic); limit 60s
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
endpoint  tcp://127.0.0.1:8080
...

Here is what happened:

  1. cairn pulled the nginx image. Your first deploy of an image takes longer because of this download. Later deploys use the cached copy.
  2. It turned the image into a disk and booted a VM from it.
  3. It waited until nginx accepted connections on port 80 before it called the deploy a success. If that never happens within 60 seconds (--wait-timeout changes the limit), the deploy fails and the previous version, if there is one, starts again.

Now try it:

sh
curl http://127.0.0.1:8080/

You get nginx's welcome page, served from inside the VM.

Step 4: see what is running ​

sh
cairn ps
text
APP  ROLE     STATE    HEALTH  TIME   RESTARTS  ENDPOINTS              MACHINE
web  current  running  -       up 5s  0         tcp://127.0.0.1:8080   YJ449SSML5

cairn ps lists all your apps. For one app in detail, run cairn status:

sh
cairn status web
text
app       web
state     running
machine   YJ449SSML5
uptime    5s
endpoint  tcp://127.0.0.1:8080
console   ~/.cairn/apps/web/machines/YJ449SSML5/console.log
restart   on-failure
...

The console line is your app's output. Anything nginx prints to stdout or stderr ends up in that file:

sh
tail -f ~/.cairn/apps/web/machines/YJ449SSML5/console.log

Step 5: run commands inside the VM ​

sh
cairn exec web -- nginx -v     # run one command
cairn console web              # open a shell; type ~. to leave

Step 6: stop, start, destroy ​

sh
cairn stop web       # shut the VM down; its disk and port are kept
cairn start web      # boot it again, exactly as it was
cairn destroy web    # delete the app and its VM

destroy doesn't delete volumes (your persistent data) or the app's network unless you ask. It prints how to remove them.

Change something and redeploy ​

Edit cairn.toml, for example to give the VM more memory:

toml
[vm]
memory = "1gb"

Then run cairn deploy again. cairn builds a new VM, stops the old one, starts the new one, and waits until it is ready. Your app is unavailable for a moment while this happens.

The root disk is rebuilt on every deploy

Every deploy builds the VM's disk fresh from the image, so anything your app wrote to its own disk is gone afterwards. Put data you want to keep on a volume.

Next ​