Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ Experimental features:
- [`./docs/freebsd.md`](./docs/freebsd.md): Running FreeBSD jails
- [`./docs/ipfs.md`](./docs/ipfs.md): Distributing images on IPFS
- [`./docs/builder-debug.md`](./docs/builder-debug.md): Interactive debugging of Dockerfile
- [`./docs/nerdbox.md`](./docs/nerdbox.md): Running Linux containers on macOS using nerdbox

Implementation details:

Expand Down
50 changes: 50 additions & 0 deletions docs/nerdbox.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# nerdbox (experimental)

| :zap: Requirement | nerdctl >= 2.2, containerd >= 2.2 |
|-------------------|-----------------------------------|


nerdctl supports [nerdbox](https://github.com/containerd/nerdbox) experimentally
for running Linux containers, including non-Linux hosts such as macOS.

## Prerequisites
- [nerdbox](https://github.com/containerd/nerdbox) with its dependencies

- `/var/lib/nerdctl` directory chowned for the current user:
```bash
sudo mkdir -p /var/lib/nerdctl
sudo chown $(whoami):staff /var/lib/nerdctl
```

## Usage

```bash
nerdctl run \
--rm \
--snapshotter erofs \
--runtime io.containerd.nerdbox.v1 \
--platform=linux/arm64 \
--net=host \
--log-driver=none \
hello-world
```
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WIP. Still does not work:

FATA[0005] failed to create shim task: VM did not start within 5s


Lots of CLI flags still do not work.

## FAQ
### How is nerdbox comparable to Lima ?

The following table compares nerdbox and [Lima](https://lima-vm.io/)
on macOS for running Linux containers:

| | nerdbox | Lima |
|-----------------------|---------|-------------|
| #VM : #Container | 1:1 | 1:N |
| VM image | minimal | full Ubuntu |
| containerd running on | host | inside VM |
| Low-level runtime | krun | runc |
| Snapshotter | erofs | overlayfs |

See also:
- https://github.com/containerd/nerdbox
- https://lima-vm.io/docs/examples/containers/containerd/
14 changes: 10 additions & 4 deletions pkg/cmd/container/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,15 @@ func Create(ctx context.Context, client *containerd.Client, args []string, netMa
return nil, nil, err
}

opts = append(opts,
oci.WithDefaultSpec(),
)
if options.Platform == "" {
opts = append(opts,
oci.WithDefaultSpec(),
)
} else {
opts = append(opts,
oci.WithDefaultSpecForPlatform(options.Platform),
)
}

platformOpts, err := setPlatformOptions(ctx, client, id, netManager.NetworkOptions().UTSNamespace, &internalLabels, options)
if err != nil {
Expand Down Expand Up @@ -303,7 +309,7 @@ func Create(ctx context.Context, client *containerd.Client, args []string, netMa
// The OCI hooks we define (whose logic can be found in pkg/ocihook) primarily
// perform network setup and teardown when using CNI networking.
// On Windows, we are forced to set up and tear down the networking from within nerdctl.
if runtime.GOOS != "windows" {
if runtime.GOOS != "windows" && runtime.GOOS != "darwin" {
hookOpt, err := withNerdctlOCIHook(options.NerdctlCmd, options.NerdctlArgs)
if err != nil {
return nil, generateRemoveOrphanedDirsFunc(ctx, id, dataStore, internalLabels), err
Expand Down
7 changes: 5 additions & 2 deletions pkg/cmd/container/run_mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ func generateMountOpts(ctx context.Context, client *containerd.Client, ensuredIm
}
}

if runtime.GOOS == "linux" {
switch runtime.GOOS {
case "linux":
defer unmounter(tempDir)
for _, m := range mounts {
m := m
Expand All @@ -213,7 +214,9 @@ func generateMountOpts(ctx context.Context, client *containerd.Client, ensuredIm
return nil, nil, nil, fmt.Errorf("failed to mount %+v on %q: %w", m, tempDir, err)
}
}
} else {
case "darwin":
// NOP
default:
defer unmounter(tempDir)
if err := mount.All(mounts, tempDir); err != nil {
if err := s.Remove(ctx, tempDir); err != nil && !errdefs.IsNotFound(err) {
Expand Down
Loading