|
| 1 | +# Zig "Hello, world!" |
| 2 | + |
| 3 | +This directory contains a Zig-based "Hello, world!" example running on Unikraft. |
| 4 | + |
| 5 | +## Set Up |
| 6 | + |
| 7 | +To run this example, [install Unikraft's companion command-line toolchain `kraft`](https://unikraft.org/docs/cli), clone this repository and `cd` into this directory. |
| 8 | + |
| 9 | +## Run and Use |
| 10 | + |
| 11 | +Use `kraft` to run the image and start a Unikraft instance: |
| 12 | + |
| 13 | +```bash |
| 14 | +kraft run --rm --plat qemu --arch x86_64 . |
| 15 | +``` |
| 16 | + |
| 17 | +If the `--plat` argument is left out, it defaults to `qemu`. |
| 18 | +If the `--arch` argument is left out, it defaults to your system's CPU architecture. |
| 19 | + |
| 20 | +Once executed, you should see a "Bye, World!" message. |
| 21 | + |
| 22 | +## Inspect and Close |
| 23 | + |
| 24 | +To list information about the Unikraft instance, use: |
| 25 | + |
| 26 | +```bash |
| 27 | +kraft ps |
| 28 | +``` |
| 29 | + |
| 30 | +```text |
| 31 | +NAME KERNEL ARGS CREATED STATUS MEM PORTS PLAT |
| 32 | +elastic_goblin oci://unikraft.org/base:latest /helloworld 9 seconds ago running 64M qemu/x86_64 |
| 33 | +``` |
| 34 | + |
| 35 | +The instance name is `elastic_goblin`. |
| 36 | +To close the Unikraft instance, close the `kraft` process (e.g., via `Ctrl+c`) or run: |
| 37 | + |
| 38 | +```bash |
| 39 | +kraft rm elastic_goblin |
| 40 | +``` |
| 41 | + |
| 42 | +Note that depending on how you modify this example your instance **may** need more memory to run. |
| 43 | +To do so, use the `kraft run`'s `-M` flag, for example: |
| 44 | + |
| 45 | +```bash |
| 46 | +kraft run --rm --plat qemu --arch x86_64 -M 256M . |
| 47 | +``` |
| 48 | + |
| 49 | +## `kraft` and `sudo` |
| 50 | + |
| 51 | +Mixing invocations of `kraft` and `sudo` can lead to unexpected behavior. |
| 52 | +Read more about how to start `kraft` without `sudo` at [https://unikraft.org/sudoless](https://unikraft.org/sudoless). |
| 53 | + |
| 54 | +## Learn More |
| 55 | + |
| 56 | +- [How to run unikernels locally](https://unikraft.org/docs/cli/running) |
| 57 | +- [Building `Dockerfile` Images with `BuildKit`](https://unikraft.org/guides/building-dockerfile-images-with-buildkit) |
0 commit comments