Merge pull request #8098 from vrothberg/fix-8082

container create: record correct image name
This commit is contained in:
OpenShift Merge Robot
2020-10-22 11:03:46 -04:00
committed by GitHub
3 changed files with 33 additions and 5 deletions

View File

@ -469,7 +469,7 @@ func (ir *Runtime) getLocalImage(inputName string) (string, *storage.Image, erro
if err != nil { if err != nil {
return "", nil, err return "", nil, err
} }
img, err := ir.store.Image(ref.String()) img, err := ir.store.Image(reference.TagNameOnly(ref).String())
if err == nil { if err == nil {
return ref.String(), img, nil return ref.String(), img, nil
} }

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"os" "os"
"path/filepath" "path/filepath"
"strings"
"github.com/containers/common/pkg/config" "github.com/containers/common/pkg/config"
"github.com/containers/podman/v2/libpod" "github.com/containers/podman/v2/libpod"
@ -91,11 +92,19 @@ func MakeContainer(ctx context.Context, rt *libpod.Runtime, s *specgen.SpecGener
if err != nil { if err != nil {
return nil, err return nil, err
} }
imgName := s.Image // If the input name changed, we could properly resolve the
names := newImage.Names() // image. Otherwise, it must have been an ID where we're
if len(names) > 0 { // defaulting to the first name or an empty one if no names are
imgName = names[0] // present.
imgName := newImage.InputName
if s.Image == newImage.InputName && strings.HasPrefix(newImage.ID(), s.Image) {
imgName = ""
names := newImage.Names()
if len(names) > 0 {
imgName = names[0]
}
} }
options = append(options, libpod.WithRootFSFromImage(newImage.ID(), imgName, s.RawImageName)) options = append(options, libpod.WithRootFSFromImage(newImage.ID(), imgName, s.RawImageName))
} }
if err := s.Validate(); err != nil { if err := s.Validate(); err != nil {

View File

@ -473,4 +473,23 @@ json-file | f
run_podman kill $cid run_podman kill $cid
} }
# Regression test for issue #8082
@test "podman run : look up correct image name" {
# Create a 2nd tag for the local image.
local name="localhost/foo/bar"
run_podman tag $IMAGE $name
# Create a container with the 2nd tag and make sure that it's being
# used. #8082 always inaccurately used the 1st tag.
run_podman create $name
cid="$output"
run_podman inspect --format "{{.ImageName}}" $cid
is "$output" "$name"
# Clean up.
run_podman rm $cid
run_podman untag $IMAGE $name
}
# vim: filetype=sh # vim: filetype=sh