|
2 | 2 | title: Examples
|
3 | 3 | weight: 3
|
4 | 4 | ---
|
5 |
| -## uname |
6 |
| -```console |
7 |
| -$ uname -a |
8 |
| -Darwin macbook.local 20.4.0 Darwin Kernel Version 20.4.0: Thu Apr 22 21:46:47 PDT 2021; root:xnu-7195.101.2~1/RELEASE_X86_64 x86_64 |
9 | 5 |
|
10 |
| -$ lima uname -a |
11 |
| -Linux lima-default 5.11.0-16-generic #17-Ubuntu SMP Wed Apr 14 20:12:43 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux |
| 6 | +## Running Linux commands |
| 7 | +```bash |
| 8 | +lima sudo apt-get install -y neofetch |
| 9 | +lima neofetch |
| 10 | +``` |
| 11 | + |
| 12 | +## Accessing host files |
| 13 | + |
| 14 | +By default, the VM has read-only accesses to `/Users/<USERNAME>` and read-write accesses to `/tmp/lima`. |
12 | 15 |
|
13 |
| -$ LIMA_INSTANCE=arm lima uname -a |
14 |
| -Linux lima-arm 5.11.0-16-generic #17-Ubuntu SMP Wed Apr 14 20:10:16 UTC 2021 aarch64 aarch64 aarch64 GNU/Linux |
| 16 | +To allow writing to `/Users/<USERNAME>`: |
| 17 | +```bash |
| 18 | +limactl edit --mount-writable --mount-type=virtiofs |
15 | 19 | ```
|
16 |
| -{{% fixlinks %}} |
17 |
| -See [`./docs/multi-arch.md`](./docs/multi-arch.md) for Intel-on-ARM and ARM-on-Intel . |
18 |
| -{{% /fixlinks %}} |
19 |
| -## Sharing files across macOS and Linux |
20 |
| -```console |
21 |
| -$ echo "files under /Users on macOS filesystem are readable from Linux" > some-file |
22 | 20 |
|
23 |
| -$ lima cat some-file |
24 |
| -files under /Users on macOS filesystem are readable from Linux |
| 21 | +Specifying `--mount-type=virtiofs` is not necessary here, but it is highly recommended |
| 22 | +for the best performance and stability. |
25 | 23 |
|
26 |
| -$ lima sh -c 'echo "/tmp/lima is writable from both macOS and Linux" > /tmp/lima/another-file' |
| 24 | +## Running containers |
| 25 | +{{< tabpane text=true >}} |
| 26 | + |
| 27 | +{{% tab header="containerd" %}} |
| 28 | +```bash |
| 29 | +nerdctl.lima run -d --name nginx -p 127.0.0.1:8080:80 nginx:alpine |
| 30 | +``` |
| 31 | +{{% /tab %}} |
27 | 32 |
|
28 |
| -$ cat /tmp/lima/another-file |
29 |
| -/tmp/lima is writable from both macOS and Linux |
| 33 | +{{% tab header="Docker" %}} |
| 34 | +```bash |
| 35 | +limactl start template://docker |
| 36 | +export DOCKER_HOST=$(limactl list docker --format 'unix://{{.Dir}}/sock/docker.sock') |
| 37 | +docker run -d --name nginx -p 127.0.0.1:8080:80 nginx:alpine |
30 | 38 | ```
|
| 39 | +{{% /tab %}} |
31 | 40 |
|
32 |
| -## Running containerd containers (compatible with Docker containers) |
33 |
| -```console |
34 |
| -$ lima nerdctl run -d --name nginx -p 127.0.0.1:8080:80 nginx:alpine |
| 41 | +{{% tab header="Kubernetes" %}} |
| 42 | +```bash |
| 43 | +limactl start template://k8s |
| 44 | +export KUBECONFIG=$(limactl list k8s --format 'unix://{{.Dir}}/copied-from-guest/kubeconfig.yaml') |
| 45 | +kubectl apply -f ... |
35 | 46 | ```
|
| 47 | +{{% /tab %}} |
36 | 48 |
|
37 |
| -> You don't need to run "lima nerdctl" everytime, instead you can use special shortcut called "nerdctl.lima" to do the same thing. By default, it'll be installed along with the lima, so, you don't need to do anything extra. There will be a symlink called nerdctl pointing to nerdctl.lima. This is only created when there is no nerdctl entry in the directory already though. It worths to mention that this is created only via make install. Not included in Homebrew/MacPorts/nix packages. |
| 49 | +{{< /tabpane >}} |
38 | 50 |
|
39 |
| -<http://127.0.0.1:8080> is accessible from both macOS and Linux. |
| 51 | +- <http://127.0.0.1:8080> is accessible from the host, as well as from the VM. |
| 52 | + |
| 53 | +- For the usage of containerd and nerdctl (contaiNERD ctl), visit <https://github.com/containerd/containerd> |
| 54 | +and <https://github.com/containerd/nerdctl>. |
| 55 | + |
| 56 | +- If you have installed Lima by `make install`, the `nerdctl.lima` command is also available as `nerdctl`. |
| 57 | + If you have installed Lima by `brew install lima`, you may make an alias (or a symlink) by yourself: |
| 58 | + `alias nerdctl=nerdctl.lima` |
| 59 | + |
| 60 | +## Advanced configuration |
| 61 | + |
| 62 | +```bash |
| 63 | +limactl start \ |
| 64 | + --name=default \ |
| 65 | + --cpus=4 \ |
| 66 | + --memory=8 \ |
| 67 | + --vm-type=vz \ |
| 68 | + --rosetta \ |
| 69 | + --mount-type=virtiofs \ |
| 70 | + --mount-writable \ |
| 71 | + --network=vzNAT \ |
| 72 | + template://fedora |
| 73 | +``` |
40 | 74 |
|
41 |
| -For the usage of containerd and nerdctl (contaiNERD ctl), visit <https://github.com/containerd/containerd> and <https://github.com/containerd/nerdctl>. |
| 75 | +- `--name=default`: Set the instance name to "default" |
| 76 | +- `--cpus=4`: Set the number of the CPUs to 4 |
| 77 | +- `--memory=8`: Set the amount of the memory to 8 GiB |
| 78 | +- `--vm-type=vz`: Use Apple's Virtualization.framework (vz) to enable Rosetta, virtiofs, and vzNAT |
| 79 | +- `--rosetta`: Allow running Intel (AMD) binaries on ARM |
| 80 | +- `--mount-type=virtiofs`: Use virtiofs for better performance |
| 81 | +- `--mount-writable`: Make the home mount (`/Users/<USERNAME>`) writable |
| 82 | +- `--network=vzNAT`: Make the VM reachable from the host by its IP address |
| 83 | +- `template://fedora`: Use Fedora |
0 commit comments