diff --git a/pkg/api/handlers/compat/containers_create.go b/pkg/api/handlers/compat/containers_create.go index 03acff66e4..3856d09bef 100644 --- a/pkg/api/handlers/compat/containers_create.go +++ b/pkg/api/handlers/compat/containers_create.go @@ -11,6 +11,8 @@ import ( "strconv" "strings" + "github.com/containers/buildah/pkg/parse" + "github.com/containers/common/libimage" "github.com/containers/common/libnetwork/types" "github.com/containers/common/pkg/cgroups" "github.com/containers/common/pkg/config" @@ -33,7 +35,8 @@ func CreateContainer(w http.ResponseWriter, r *http.Request) { runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime) decoder := r.Context().Value(api.DecoderKey).(*schema.Decoder) query := struct { - Name string `schema:"name"` + Name string `schema:"name"` + Platform string `schema:"platform"` }{ // override any golang type defaults } @@ -69,7 +72,16 @@ func CreateContainer(w http.ResponseWriter, r *http.Request) { } body.Config.Image = imageName - newImage, resolvedName, err := runtime.LibimageRuntime().LookupImage(body.Config.Image, nil) + lookupImageOptions := libimage.LookupImageOptions{} + if query.Platform != "" { + var err error + lookupImageOptions.OS, lookupImageOptions.Architecture, lookupImageOptions.Variant, err = parse.Platform(query.Platform) + if err != nil { + utils.Error(w, http.StatusBadRequest, fmt.Errorf("parsing platform: %w", err)) + return + } + } + newImage, resolvedName, err := runtime.LibimageRuntime().LookupImage(body.Config.Image, &lookupImageOptions) if err != nil { if errors.Is(err, storage.ErrImageUnknown) { utils.Error(w, http.StatusNotFound, fmt.Errorf("no such image: %w", err)) diff --git a/test/apiv2/20-containers.at b/test/apiv2/20-containers.at index 7840ea5242..3a38976e73 100644 --- a/test/apiv2/20-containers.at +++ b/test/apiv2/20-containers.at @@ -624,3 +624,14 @@ fi rm -rf $TMPD podman container rm -fa + +# 18951: Make sure container create supports the platform parameter. Force an +# initial architecture to make sure the test runs on all platforms. +podman pull --platform=linux/amd64 $IMAGE +t POST containers/create?platform=linux/amd64 \ + Image=$IMAGE \ + 201 +t POST containers/create?platform=linux/aarch64 \ + Image=$IMAGE \ + 404 +podman rmi -f $IMAGE