diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-12-11 10:20:16 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-11 10:20:16 -0500 |
commit | 99ac30a88287e2c174e69812293f6b130f7a67d5 (patch) | |
tree | 7af3995e5609a86e21fa61b54cc25ec72761ec8e /pkg/api/handlers | |
parent | 335c59e7dcd06429c56c0f58e859f7694fcbc891 (diff) | |
parent | fb25f737e527279132a1572552ba12084a03f597 (diff) | |
download | podman-99ac30a88287e2c174e69812293f6b130f7a67d5.tar.gz podman-99ac30a88287e2c174e69812293f6b130f7a67d5.tar.bz2 podman-99ac30a88287e2c174e69812293f6b130f7a67d5.zip |
Merge pull request #8690 from zhangguanzhang/apiv2-wrong-ImgName
Fix Wrong img name used when creating a container from an image which had multi names
Diffstat (limited to 'pkg/api/handlers')
-rw-r--r-- | pkg/api/handlers/compat/containers_create.go | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/pkg/api/handlers/compat/containers_create.go b/pkg/api/handlers/compat/containers_create.go index 409a74de2..6e85872b2 100644 --- a/pkg/api/handlers/compat/containers_create.go +++ b/pkg/api/handlers/compat/containers_create.go @@ -66,7 +66,20 @@ func CreateContainer(w http.ResponseWriter, r *http.Request) { utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "make cli opts()")) return } - sg := specgen.NewSpecGenerator(newImage.ID(), cliOpts.RootFS) + + imgNameOrID := newImage.ID() + // if the img had multi names with the same sha256 ID, should use the InputName, not the ID + if len(newImage.Names()) > 1 { + imageRef, err := utils.ParseDockerReference(newImage.InputName) + if err != nil { + utils.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest, err) + return + } + // maybe the InputName has no tag, so use full name to display + imgNameOrID = imageRef.DockerReference().String() + } + + sg := specgen.NewSpecGenerator(imgNameOrID, cliOpts.RootFS) if err := common.FillOutSpecGen(sg, cliOpts, args); err != nil { utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "fill out specgen")) return |