diff --git a/pkg/cidata/cidata.TEMPLATE.d/boot/40-install-containerd.sh b/pkg/cidata/cidata.TEMPLATE.d/boot/40-install-containerd.sh index aa7843b2c28..0ab8e364de5 100644 --- a/pkg/cidata/cidata.TEMPLATE.d/boot/40-install-containerd.sh +++ b/pkg/cidata/cidata.TEMPLATE.d/boot/40-install-containerd.sh @@ -45,6 +45,8 @@ if [ "${LIMA_CIDATA_CONTAINERD_SYSTEM}" = 1 ]; then mkdir -p /etc/containerd /etc/buildkit cat >"/etc/containerd/config.toml" <"${LIMA_CIDATA_HOME}/.config/containerd/config.toml" </etc/init.d/rosettad </etc/systemd/system/rosettad.service </etc/cdi/rosetta.yaml < + ------ + See: https://lima-vm.io/docs/config/multi-arch/#rosetta-aot-caching + {{- end}} param: containerdSnapshotter: false diff --git a/templates/docker.yaml b/templates/docker.yaml index 9932f7c3900..de356d48cb2 100644 --- a/templates/docker.yaml +++ b/templates/docker.yaml @@ -37,7 +37,9 @@ provision: apt-get install -y uidmap dbus-user-session - mode: yq path: "{{.Home}}/.config/docker/daemon.json" - expression: .features.containerd-snapshotter = {{.Param.containerdSnapshotter}} + expression: | + .features.cdi = true | + .features.containerd-snapshotter = {{.Param.containerdSnapshotter}} owner: "{{.User}}" - mode: user script: | @@ -74,5 +76,22 @@ message: | docker context use lima-{{.Name}} docker run hello-world ------ + {{- if .Instance.Config.VMOpts.VZ.Rosetta.Enabled}} + Rosetta is enabled in this VM, so you can run x86_64 containers on Apple Silicon. + You can use Rosetta AOT Caching with the CDI spec: + - To run a container, add `--device=lima-vm.io/rosetta=cached` to your `docker run` command: + ------ + docker run --platform=linux/amd64 --device=lima-vm.io/rosetta=cached ... + ------ + - To build an image, add `# syntax=docker/dockerfile:1-labs` at the top of your Dockerfile, + and use `--device=lima-vm.io/rosetta=cached` in the `RUN` command: + ------ + # syntax=docker/dockerfile:1-labs + FROM ... + ... + RUN --device=lima-vm.io/rosetta=cached + ------ + See: https://lima-vm.io/docs/config/multi-arch/#rosetta-aot-caching + {{- end}} param: containerdSnapshotter: false diff --git a/website/content/en/docs/config/multi-arch.md b/website/content/en/docs/config/multi-arch.md index ee77f07228f..bbe90ede19e 100644 --- a/website/content/en/docs/config/multi-arch.md +++ b/website/content/en/docs/config/multi-arch.md @@ -86,3 +86,52 @@ rosetta: ``` {{% /tab %}} {{< /tabpane >}} + +### [Enable Rosetta AOT Caching with CDI spec](#rosetta-aot-caching) +| ⚡ Requirement | Lima >= 2.0, macOS >= 14.0, ARM | +|-------------------|----------------------------------| + +Rosetta AOT Caching speeds up containers by saving translated binaries, so they don't need to be translated again. +Learn more: [WWDC2023 video](https://developer.apple.com/videos/play/wwdc2023/10007/?time=721) + +**How to use Rosetta AOT Caching:** + +- **Run a container:** + Add `--device=lima-vm.io/rosetta=cached` to your `docker run` command: + ```bash + docker run --platform=linux/amd64 --device=lima-vm.io/rosetta=cached ... + ``` + +- **Build an image:** + Add `# syntax=docker/dockerfile:1-labs` at the top of your Dockerfile to enable the `--device` option. + Use `--device=lima-vm.io/rosetta=cached` in your `RUN` command: + ```Dockerfile + # syntax=docker/dockerfile:1-labs + FROM ... + ... + RUN --device=lima-vm.io/rosetta=cached + ``` + +- **Check if caching works:** + Look for cache files in the VM: + ```bash + limactl shell {{.Name}} ls -la /var/cache/rosettad + docker run --platform linux/amd64 --device=lima-vm.io/rosetta=cached ubuntu echo hello + limactl shell {{.Name}} ls -la /var/cache/rosettad + # You should see *.aotcache files here + ``` + +- **Check if Docker recognizes the CDI device:** + Look for CDI info in the output of `docker info`: + ```console + docker info + ... + CDI spec directories: + /etc/cdi + /var/run/cdi + Discovered Devices: + cdi: lima-vm.io/rosetta=cached + ``` + +- **Learn more about CDI:** + [CDI spec documentation](https://github.com/cncf-tags/container-device-interface/blob/main/SPEC.md)