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:
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 computerappis the name you will use in every other command.imageis any image you coulddocker pullorpodman pull.[[services]]says which port your app serves. The[[services.ports]]entry publishes it on your computer. By default it is published on127.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)
cairn deploy --dry-runThis shows everything cairn is about to do, with each default filled in, and changes nothing:
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
cairn deploygetting 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:
- cairn pulled the nginx image. Your first deploy of an image takes longer because of this download. Later deploys use the cached copy.
- It turned the image into a disk and booted a VM from it.
- It waited until nginx accepted connections on port 80 before it called the deploy a success. If that never happens within 60 seconds (
--wait-timeoutchanges the limit), the deploy fails and the previous version, if there is one, starts again.
Now try it:
curl http://127.0.0.1:8080/You get nginx's welcome page, served from inside the VM.
Step 4: see what is running
cairn psAPP ROLE STATE HEALTH TIME RESTARTS ENDPOINTS MACHINE
web current running - up 5s 0 tcp://127.0.0.1:8080 YJ449SSML5cairn ps lists all your apps. For one app in detail, run cairn status:
cairn status webapp 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:
tail -f ~/.cairn/apps/web/machines/YJ449SSML5/console.logStep 5: run commands inside the VM
cairn exec web -- nginx -v # run one command
cairn console web # open a shell; type ~. to leaveStep 6: stop, start, destroy
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 VMdestroy 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:
[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
- Use your own image: set
imageto it, or build from a Dockerfile with a[build]table. - Add a health check or restart rules: Health and restarts. Change the stop signal: Deploying.
- Keep data across deploys: Volumes.
- Connect two apps, or limit which sites an app can reach: Networking.
- Learn the words cairn uses: Concepts.