From 2a8d301177f3f04438dd2e4677282f17f341f442 Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Tue, 14 Oct 2025 23:30:24 -0700 Subject: [PATCH] Set default run platform in ctr Currently run will generate invalid specifications on non-Linux Unix platforms. Linux should be the default container platform for run when the platform is not explicitly provided. Signed-off-by: Derek McGowan --- cmd/ctr/commands/run/run_unix.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/cmd/ctr/commands/run/run_unix.go b/cmd/ctr/commands/run/run_unix.go index 1b0008b852..7cc9f110b7 100644 --- a/cmd/ctr/commands/run/run_unix.go +++ b/cmd/ctr/commands/run/run_unix.go @@ -97,6 +97,24 @@ func NewContainer(ctx context.Context, client *containerd.Client, cliContext *cl id = cliContext.Args().Get(1) } + platform := cliContext.String("platform") + if platform == "" { + plat := platforms.DefaultSpec() + switch plat.OS { + case "linux": + case "freebsd": + // TODO: freebsd support is under development, allow platform to remain unchanged. + // A freebsd spec generator must be implemented to make use of it, until then, + // either a spec must be provided or the runtime can convert from the linux spec. + default: + // Other OSes do not have a supported container runtime, to use experimental runtimes, + // specs must be explicitly provided. Once there is a support spec generator, then + // the default platform can be added above to not default to linux. + plat.OS = "linux" + } + platform = platforms.FormatAll(plat) + } + var ( opts []oci.SpecOpts cOpts []containerd.NewContainerOpts @@ -116,7 +134,7 @@ func NewContainer(ctx context.Context, client *containerd.Client, cliContext *cl // for container's id is Args[1] args = cliContext.Args().Slice()[2:] ) - opts = append(opts, oci.WithDefaultSpec(), oci.WithDefaultUnixDevices) + opts = append(opts, oci.WithDefaultSpecForPlatform(platform), oci.WithDefaultUnixDevices) if ef := cliContext.String("env-file"); ef != "" { opts = append(opts, oci.WithEnvFile(ef)) }