|
| 1 | +--- |
| 2 | +title: containerd (Default) |
| 3 | +weight: 1 |
| 4 | +--- |
| 5 | + |
| 6 | +Lima comes with the built-in integration for [containerd](https://containerd.io) and |
| 7 | +[nerdctl](https://github.com/containerd/nerdctl) (contaiNERD CTL): |
| 8 | + |
| 9 | +{{< tabpane text=true >}} |
| 10 | +{{% tab header="Rootless" %}} |
| 11 | +```bash |
| 12 | +lima nerdctl run -d --name nginx -p 127.0.0.1:8080:80 nginx:alpine |
| 13 | +``` |
| 14 | + |
| 15 | +or |
| 16 | + |
| 17 | +```bash |
| 18 | +nerdctl.lima run -d --name nginx -p 127.0.0.1:8080:80 nginx:alpine |
| 19 | +``` |
| 20 | + |
| 21 | + |
| 22 | +- If you have installed Lima by [`make install`](../../installation/source.md), the `nerdctl.lima` command is also available as `nerdctl`. |
| 23 | +- If you have installed Lima by [`brew install lima`](../../installation/_index.md), you may make an alias (or a symlink) by yourself: |
| 24 | + `alias nerdctl=nerdctl.lima` |
| 25 | +{{% /tab %}} |
| 26 | +{{% tab header="Rootful" %}} |
| 27 | +```bash |
| 28 | +limactl start --containerd=system |
| 29 | +lima sudo nerdctl run -d --name nginx -p 127.0.0.1:8080:80 nginx:alpine |
| 30 | +``` |
| 31 | +{{% /tab %}} |
| 32 | +{{< /tabpane >}} |
| 33 | + |
| 34 | +The usage of the `nerdctl` command is similar to the `docker` command. See the [Command Reference](https://github.com/containerd/nerdctl/blob/main/docs/command-reference.md). |
| 35 | + |
| 36 | +## Advanced features |
| 37 | +### Enhanced supply chain security with gomodjail |
| 38 | + |
| 39 | +[gomodjail](https://github.com/AkihiroSuda/gomodjail) is an experimental library sandbox for Go modules. |
| 40 | + |
| 41 | +gomodjail imposes syscall restrictions on a specific set of Go modules, so as to mitigate their potential vulnerabilities and supply chain attack vectors. |
| 42 | +A restricted module is hindered to access files and execute commands. |
| 43 | + |
| 44 | +gomodjail can be enabled for nerdctl by using the `nerdctl.gomodjail` binary. |
| 45 | + |
| 46 | +```bash |
| 47 | +lima nerdctl.gomodjail ... |
| 48 | +``` |
| 49 | + |
| 50 | +For the gomodjail policy applied to `nerdctl.gomodjail`, see <https://github.com/containerd/nerdctl/blob/main/go.mod>. |
| 51 | + |
| 52 | +### Accelerating rootless networking with bypass4netns |
| 53 | + |
| 54 | +[bypass4netns](https://github.com/rootless-containers/bypass4netns) is an experimental accelerator for rootless networking. |
| 55 | + |
| 56 | +On macOS hosts, it is highly recommended to use the [vzNAT](../../config/network/vmnet.md#vznat) networking in conjunction |
| 57 | +to reduce the overhead of Lima's user-mode networking: |
| 58 | + |
| 59 | +```bash |
| 60 | +limactl start --network vzNAT |
| 61 | +``` |
| 62 | + |
| 63 | +To enable bypass4netns, the daemon process (`bypass4netnsd`) has to be installed in the VM as follows: |
| 64 | +<!-- TODO: install by default --> |
| 65 | +```bash |
| 66 | +lima containerd-rootless-setuptool.sh install-bypass4netnsd |
| 67 | +``` |
| 68 | + |
| 69 | +Then run a container with an annotation `nerdctl/bypass4netns=true`: |
| 70 | + |
| 71 | +```bash |
| 72 | +# 192.168.64.1 is the IP address of the "bridge100" interface on the macOS host |
| 73 | +lima nerdctl run --annotation nerdctl/bypass4netns=true alpine \ |
| 74 | + sh -euc 'apk add iperf3 && iperf3 -c 192.168.64.1' |
| 75 | +``` |
| 76 | + |
| 77 | +Benchmark result: |
| 78 | + |
| 79 | +| Mode | Throughput | |
| 80 | +|-------------------------------|----------------| |
| 81 | +| Rootless without bypass4netns | 2.30 Gbits/sec | |
| 82 | +| Rootless with bypass4netns | 86.0 Gbits/sec | |
| 83 | +| Rootful | 90.3 Gbits/sec | |
| 84 | + |
| 85 | +<details> |
| 86 | +<summary>Benchmarking environment</summary> |
| 87 | +<p> |
| 88 | + |
| 89 | +- Lima version: 2.0.0-alpha.2 |
| 90 | + - nerdctl 2.1.6 |
| 91 | + - containerd 2.1.4 |
| 92 | + - bypass4netns 0.4.2 |
| 93 | +- Container: Alpine Linux 3.22.2 |
| 94 | + - iperf 3.19.1-r0 (apk) |
| 95 | +- Guest: Ubuntu 25.04 |
| 96 | +- Host: macOS 26.0.1 |
| 97 | + - iperf 3.19.1 (Homebrew) |
| 98 | +- Hardware: MacBook Pro 2024 (M4 Max, 128 GiB) |
| 99 | + |
| 100 | +</p> |
| 101 | +</details> |
| 102 | + |
| 103 | +### Accelerating start-up time with eStargz |
| 104 | + |
| 105 | +[eStargz](https://github.com/containerd/stargz-snapshotter) is an OCI-compatible container image format |
| 106 | +that reduces start-up latency using lazy-pulling technique. |
| 107 | + |
| 108 | +The support for eStargz is available by default for `ubuntu-24.04` instances: |
| 109 | + |
| 110 | +```bash |
| 111 | +limactl start --name=default template://ubuntu-24.04 |
| 112 | +``` |
| 113 | + |
| 114 | +The latest Ubuntu will be supported too in [a future release](https://github.com/containerd/stargz-snapshotter/issues/2144). |
| 115 | + |
| 116 | +{{% alert title="Hint" color=success %}} |
| 117 | +ARM Mac users need to run `limactl start` with `--rosetta` to allow [running AMD64 binaries](../../config/multi-arch.md). |
| 118 | +This is not an architectural limitation of eStargz, however, Rosetta is needed because the example Python image below |
| 119 | +is currently [only available for AMD64](https://github.com/containerd/stargz-snapshotter/issues/2143). |
| 120 | +{{% /alert %}} |
| 121 | + |
| 122 | +Without eStargz: |
| 123 | + |
| 124 | +```console |
| 125 | +$ time lima nerdctl run --platform=amd64 ghcr.io/stargz-containers/python:3.13-org python3 -c 'print("hi")' |
| 126 | +[...] |
| 127 | +hi |
| 128 | + |
| 129 | +real 0m23.767s |
| 130 | +user 0m0.025s |
| 131 | +sys 0m0.020s |
| 132 | +``` |
| 133 | + |
| 134 | +With eStargz: |
| 135 | + |
| 136 | +```console |
| 137 | +$ time lima nerdctl --snapshotter=stargz run --platform=amd64 ghcr.io/stargz-containers/python:3.13-esgz python3 -c 'print("hi")' |
| 138 | +[...] |
| 139 | +hi |
| 140 | + |
| 141 | +real 0m13.365s |
| 142 | +user 0m0.026s |
| 143 | +sys 0m0.021s |
| 144 | +``` |
| 145 | + |
| 146 | +Examples of eStargz images can be found at |
| 147 | +<https://github.com/containerd/stargz-snapshotter/blob/main/docs/pre-converted-images.md>. |
| 148 | + |
| 149 | +See also: |
| 150 | +- https://github.com/containerd/stargz-snapshotter |
| 151 | +- https://github.com/containerd/nerdctl/blob/main/docs/stargz.md |
| 152 | + |
| 153 | +## Disabling containerd |
| 154 | + |
| 155 | +To disable containerd, start an instance with `--containerd=none`: |
| 156 | + |
| 157 | +```bash |
| 158 | +limactl start --containerd=none |
| 159 | +``` |
0 commit comments