Skip to content

Commit cd1a242

Browse files
committed
Relax --runtime restrictions
Signed-off-by: apostasie <[email protected]>
1 parent 772bb09 commit cd1a242

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

cmd/nerdctl/compose/compose_up_test.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
"gotest.tools/v3/icmd"
2828

2929
"github.com/containerd/nerdctl/v2/pkg/testutil"
30-
"github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest"
3130
)
3231

3332
// https://github.com/containerd/nerdctl/issues/1942
@@ -48,11 +47,7 @@ services:
4847
c := base.ComposeCmd("-f", comp.YAMLFullPath(), "up", "-d")
4948
expected := icmd.Expected{
5049
ExitCode: 1,
51-
Err: `exec: \"invalid\": executable file not found in $PATH`,
52-
}
53-
// Docker expected err is different
54-
if nerdtest.IsDocker() {
55-
expected.Err = `unknown or invalid runtime name: invalid`
50+
Err: `invalid runtime name`,
5651
}
5752
c.Assert(expected)
5853
}

pkg/cmd/container/run_runtime.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package container
1818

1919
import (
2020
"context"
21+
"os/exec"
2122
"strings"
2223

2324
"github.com/opencontainers/runtime-spec/specs-go"
@@ -49,8 +50,14 @@ func generateRuntimeCOpts(cgroupManager, runtimeStr string) ([]containerd.NewCon
4950
runtimeOpts = nil
5051
}
5152
} else {
52-
// runtimeStr is a runc binary
53-
runcOpts.BinaryName = runtimeStr
53+
// runtimeStr may be a runc binary - check that it exists
54+
// if it does not, treat it as a runtime
55+
ex, err := exec.LookPath(runtimeStr)
56+
if err != nil {
57+
runtime = runtimeStr
58+
} else {
59+
runcOpts.BinaryName = ex
60+
}
5461
}
5562
}
5663
o := containerd.WithRuntime(runtime, runtimeOpts)

0 commit comments

Comments
 (0)