Skip to content

Commit 9d5b012

Browse files
committed
Add documentation about Rosetta AOT Caching
Signed-off-by: Norio Nomura <norio.nomura@gmail.com>
1 parent e198d52 commit 9d5b012

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

templates/docker-rootful.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,22 @@ message: |
6969
docker context use lima-{{.Name}}
7070
docker run hello-world
7171
------
72+
{{- if .Instance.Config.VMOpts.VZ.Rosetta.Enabled}}
73+
Rosetta is enabled in this VM, so you can run x86_64 containers on Apple Silicon.
74+
You can use Rosetta AOT Caching with the CDI spec:
75+
- To run a container, add `--device=lima-vm.io/rosetta=cached` to your `docker run` command:
76+
------
77+
docker run --platform=linux/amd64 --device=lima-vm.io/rosetta=cached ...
78+
------
79+
- To build an image, add `# syntax=docker/dockerfile:1-labs` at the top of your Dockerfile,
80+
and use `--device=lima-vm.io/rosetta=cached` in the `RUN` command:
81+
------
82+
# syntax=docker/dockerfile:1-labs
83+
FROM ...
84+
...
85+
RUN --device=lima-vm.io/rosetta=cached <your amd64 command>
86+
------
87+
See: https://lima-vm.io/docs/config/multi-arch/#rosetta-aot-caching
88+
{{- end}}
7289
param:
7390
containerdSnapshotter: false

templates/docker.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,22 @@ message: |
7676
docker context use lima-{{.Name}}
7777
docker run hello-world
7878
------
79+
{{- if .Instance.Config.VMOpts.VZ.Rosetta.Enabled}}
80+
Rosetta is enabled in this VM, so you can run x86_64 containers on Apple Silicon.
81+
You can use Rosetta AOT Caching with the CDI spec:
82+
- To run a container, add `--device=lima-vm.io/rosetta=cached` to your `docker run` command:
83+
------
84+
docker run --platform=linux/amd64 --device=lima-vm.io/rosetta=cached ...
85+
------
86+
- To build an image, add `# syntax=docker/dockerfile:1-labs` at the top of your Dockerfile,
87+
and use `--device=lima-vm.io/rosetta=cached` in the `RUN` command:
88+
------
89+
# syntax=docker/dockerfile:1-labs
90+
FROM ...
91+
...
92+
RUN --device=lima-vm.io/rosetta=cached <your amd64 command>
93+
------
94+
See: https://lima-vm.io/docs/config/multi-arch/#rosetta-aot-caching
95+
{{- end}}
7996
param:
8097
containerdSnapshotter: false

website/content/en/docs/config/multi-arch.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,52 @@ rosetta:
8686
```
8787
{{% /tab %}}
8888
{{< /tabpane >}}
89+
90+
### [Enable Rosetta AOT Caching with CDI spec](#rosetta-aot-caching)
91+
| ⚡ Requirement | Lima >= 2.0, macOS >= 14.0, ARM |
92+
|-------------------|----------------------------------|
93+
94+
Rosetta AOT Caching speeds up containers by saving translated binaries, so they don't need to be translated again.
95+
Learn more: [WWDC2023 video](https://developer.apple.com/videos/play/wwdc2023/10007/?time=721)
96+
97+
**How to use Rosetta AOT Caching:**
98+
99+
- **Run a container:**
100+
Add `--device=lima-vm.io/rosetta=cached` to your `docker run` command:
101+
```bash
102+
docker run --platform=linux/amd64 --device=lima-vm.io/rosetta=cached ...
103+
```
104+
105+
- **Build an image:**
106+
Add `# syntax=docker/dockerfile:1-labs` at the top of your Dockerfile to enable the `--device` option.
107+
Use `--device=lima-vm.io/rosetta=cached` in your `RUN` command:
108+
```Dockerfile
109+
# syntax=docker/dockerfile:1-labs
110+
FROM ...
111+
...
112+
RUN --device=lima-vm.io/rosetta=cached <your amd64 command>
113+
```
114+
115+
- **Check if caching works:**
116+
Look for cache files in the VM:
117+
```bash
118+
limactl shell {{.Name}} ls -la /var/cache/rosettad
119+
docker run --platform linux/amd64 --device=lima-vm.io/rosetta=cached ubuntu echo hello
120+
limactl shell {{.Name}} ls -la /var/cache/rosettad
121+
# You should see *.aotcache files here
122+
```
123+
124+
- **Check if Docker recognizes the CDI device:**
125+
Look for CDI info in the output of `docker info`:
126+
```console
127+
docker info
128+
...
129+
CDI spec directories:
130+
/etc/cdi
131+
/var/run/cdi
132+
Discovered Devices:
133+
cdi: lima-vm.io/rosetta=cached
134+
```
135+
136+
- **Learn more about CDI:**
137+
[CDI spec documentation](https://github.com/cncf-tags/container-device-interface/blob/main/SPEC.md)

0 commit comments

Comments
 (0)