diff --git a/cmd/ctr/commands/commands.go b/cmd/ctr/commands/commands.go index 5ce08f72e..bfac57986 100644 --- a/cmd/ctr/commands/commands.go +++ b/cmd/ctr/commands/commands.go @@ -141,6 +141,10 @@ var ( Usage: "Runtime name or absolute path to runtime binary", Value: defaults.DefaultRuntime, }, + cli.StringFlag{ + Name: "sandbox", + Usage: "Create the container in the given sandbox", + }, cli.StringFlag{ Name: "runtime-config-path", Usage: "Optional runtime config path", diff --git a/cmd/ctr/commands/run/run.go b/cmd/ctr/commands/run/run.go index a24d344b6..c6833aeb7 100644 --- a/cmd/ctr/commands/run/run.go +++ b/cmd/ctr/commands/run/run.go @@ -164,6 +164,7 @@ var Command = cli.Command{ return err } defer cancel() + container, err := NewContainer(ctx, client, context) if err != nil { return err diff --git a/cmd/ctr/commands/run/run_unix.go b/cmd/ctr/commands/run/run_unix.go index 28cec07de..81ba9d111 100644 --- a/cmd/ctr/commands/run/run_unix.go +++ b/cmd/ctr/commands/run/run_unix.go @@ -102,6 +102,10 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli spec containerd.NewContainerOpts ) + if sandbox := context.String("sandbox"); sandbox != "" { + cOpts = append(cOpts, containerd.WithSandbox(sandbox)) + } + if config { cOpts = append(cOpts, containerd.WithContainerLabels(commands.LabelArgs(context.StringSlice("label")))) opts = append(opts, oci.WithSpecFromFile(context.String("config"))) diff --git a/cmd/ctr/commands/run/run_windows.go b/cmd/ctr/commands/run/run_windows.go index 646b42c6a..09353a209 100644 --- a/cmd/ctr/commands/run/run_windows.go +++ b/cmd/ctr/commands/run/run_windows.go @@ -51,6 +51,10 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli config = context.IsSet("config") ) + if sandbox := context.String("sandbox"); sandbox != "" { + cOpts = append(cOpts, containerd.WithSandbox(sandbox)) + } + if config { id = context.Args().First() opts = append(opts, oci.WithSpecFromFile(context.String("config")))