Skip to content

Commit 14641a8

Browse files
committed
[WIP] Initial support for nerdbox
See docs/nerdbox.md Fix issue 4571 WIP: Does not work yet Signed-off-by: Akihiro Suda <[email protected]>
1 parent 804a8cd commit 14641a8

File tree

4 files changed

+57
-3
lines changed

4 files changed

+57
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ Experimental features:
298298
- [`./docs/freebsd.md`](./docs/freebsd.md): Running FreeBSD jails
299299
- [`./docs/ipfs.md`](./docs/ipfs.md): Distributing images on IPFS
300300
- [`./docs/builder-debug.md`](./docs/builder-debug.md): Interactive debugging of Dockerfile
301+
- [`./docs/nerdbox.md`](./docs/nerdbox.md): Running Linux containers on macOS using nerdbox
301302

302303
Implementation details:
303304

docs/nerdbox.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# nerdbox (experimental)
2+
3+
| :zap: Requirement | nerdctl >= 2.2, containerd >= 2.2 |
4+
|-------------------|-----------------------------------|
5+
6+
7+
nerdctl supports [nerdbox](https://github.com/containerd/nerdbox) experimentally
8+
for running Linux containers, including non-Linux hosts such as macOS.
9+
10+
## Prerequisites
11+
- [nerdbox](https://github.com/containerd/nerdbox) with its dependencies
12+
13+
- `/var/lib/nerdctl` directory chowned for the current user:
14+
```bash
15+
sudo mkdir -p /var/lib/nerdctl
16+
sudo chown $(whoami):staff /var/lib/nerdctl
17+
```
18+
19+
## Usage
20+
21+
```bash
22+
nerdctl run \
23+
--rm \
24+
--snapshotter erofs \
25+
--runtime io.containerd.nerdbox.v1 \
26+
--platform=linux/arm64 \
27+
--net=host \
28+
--log-driver=none \
29+
hello-world
30+
```
31+
32+
Lots of CLI flags still do not work.
33+
34+
## FAQ
35+
### How is nerdbox comparable to Lima ?
36+
37+
The following table compares nerdbox and [Lima](https://lima-vm.io/)
38+
on macOS for running Linux containers:
39+
40+
| | nerdbox | Lima |
41+
|-----------------------|---------|-------------|
42+
| #VM : #Container | 1:1 | 1:N |
43+
| VM image | minimal | full Ubuntu |
44+
| containerd running on | host | inside VM |
45+
| Low-level runtime | krun | runc |
46+
| Snapshotter | erofs | overlayfs |
47+
48+
See also:
49+
- https://github.com/containerd/nerdbox
50+
- https://lima-vm.io/docs/examples/containers/containerd/

pkg/cmd/container/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func Create(ctx context.Context, client *containerd.Client, args []string, netMa
119119
}
120120

121121
opts = append(opts,
122-
oci.WithDefaultSpec(),
122+
oci.WithDefaultSpecForPlatform(options.Platform),
123123
)
124124

125125
platformOpts, err := setPlatformOptions(ctx, client, id, netManager.NetworkOptions().UTSNamespace, &internalLabels, options)

pkg/cmd/container/run_mount.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ func generateMountOpts(ctx context.Context, client *containerd.Client, ensuredIm
194194
}
195195
}
196196

197-
if runtime.GOOS == "linux" {
197+
switch runtime.GOOS {
198+
case "linux":
198199
defer unmounter(tempDir)
199200
for _, m := range mounts {
200201
m := m
@@ -213,7 +214,9 @@ func generateMountOpts(ctx context.Context, client *containerd.Client, ensuredIm
213214
return nil, nil, nil, fmt.Errorf("failed to mount %+v on %q: %w", m, tempDir, err)
214215
}
215216
}
216-
} else {
217+
case "darwin":
218+
// NOP
219+
default:
217220
defer unmounter(tempDir)
218221
if err := mount.All(mounts, tempDir); err != nil {
219222
if err := s.Remove(ctx, tempDir); err != nil && !errdefs.IsNotFound(err) {

0 commit comments

Comments
 (0)