From 5d9b937fdc161085b2360b325aad2a6b3cc7e454 Mon Sep 17 00:00:00 2001 From: soulteary Date: Mon, 27 Jun 2022 00:14:06 +0800 Subject: [PATCH] feat: Support oci other than runsc --- sandbox/sandbox.go | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/sandbox/sandbox.go b/sandbox/sandbox.go index f65e642..227aff0 100644 --- a/sandbox/sandbox.go +++ b/sandbox/sandbox.go @@ -445,18 +445,34 @@ func startContainer(ctx context.Context) (c *Container, err error) { name := "play_run_" + randHex(8) setContainerWanted(name, true) - cmd := exec.Command("docker", "run", - "--name="+name, - "--rm", - "--tmpfs=/tmpfs:exec", - "-i", // read stdin - - "--runtime=runsc", - "--network=none", - "--memory="+fmt.Sprint(memoryLimitBytes), - - *container, - "--mode=contained") + var cmd *exec.Cmd + if _, err := os.Stat("/var/lib/docker/runsc"); err == nil { + cmd = exec.Command("docker", "run", + "--name="+name, + "--rm", + "--tmpfs=/tmpfs:exec", + "-i", // read stdin + + "--runtime=runsc", + "--network=none", + "--memory="+fmt.Sprint(memoryLimitBytes), + + *container, + "--mode=contained") + } else { + cmd = exec.Command("docker", "run", + "--name="+name, + "--rm", + "--tmpfs=/tmpfs:exec", + "-i", // read stdin + + "--network=none", + "--memory="+fmt.Sprint(memoryLimitBytes), + + *container, + "--mode=contained") + } + stdin, err := cmd.StdinPipe() if err != nil { return nil, err