From 52182421999282b4142d0e1c42e62cf363c9395b Mon Sep 17 00:00:00 2001 From: Kay Yan Date: Wed, 2 Aug 2023 17:31:46 +0000 Subject: [PATCH] Fix the --runtime option of container create is ignored Signed-off-by: Kay Yan --- cmd/nerdctl/compose_up_test.go | 4 ++-- pkg/cmd/container/run_runtime.go | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cmd/nerdctl/compose_up_test.go b/cmd/nerdctl/compose_up_test.go index ef1811fcd8e..353ad0d379b 100644 --- a/cmd/nerdctl/compose_up_test.go +++ b/cmd/nerdctl/compose_up_test.go @@ -46,10 +46,10 @@ services: c := base.ComposeCmd("-f", comp.YAMLFullPath(), "up", "-d") expected := icmd.Expected{ ExitCode: 1, - Err: `exec: \"invalid\": executable file not found in $PATH`, + Err: `failed to resolve runtime path: invalid runtime name invalid`, } if base.Target == testutil.Docker { - expected.Err = `Unknown runtime specified invalid` + expected.Err = `unknown or invalid runtime name: invalid` } c.Assert(expected) } diff --git a/pkg/cmd/container/run_runtime.go b/pkg/cmd/container/run_runtime.go index 20a121d5dad..e685fe052f4 100644 --- a/pkg/cmd/container/run_runtime.go +++ b/pkg/cmd/container/run_runtime.go @@ -18,6 +18,7 @@ package container import ( "context" + "path/filepath" "strings" "github.com/containerd/containerd" @@ -39,6 +40,7 @@ func generateRuntimeCOpts(cgroupManager, runtimeStr string) ([]containerd.NewCon runcOpts.SystemdCgroup = true } if runtimeStr != "" { + if strings.HasPrefix(runtimeStr, "io.containerd.") || runtimeStr == "wtf.sbk.runj.v1" { runtime = runtimeStr if !strings.HasPrefix(runtimeStr, "io.containerd.runc.") { @@ -47,8 +49,9 @@ func generateRuntimeCOpts(cgroupManager, runtimeStr string) ([]containerd.NewCon } runtimeOpts = nil } - } else { + } else if filepath.IsAbs(runtimeStr) { // runtimeStr is a runc binary + runtime = runtimeStr runcOpts.BinaryName = runtimeStr } }