Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

container create: record correct image name #8098

Merged
merged 1 commit into from
Oct 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libpod/image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ func (ir *Runtime) getLocalImage(inputName string) (string, *storage.Image, erro
if err != nil {
return "", nil, err
}
img, err := ir.store.Image(ref.String())
img, err := ir.store.Image(reference.TagNameOnly(ref).String())
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@baude @mheon ... this should have a quite positive effect on container creation. If the user input wasn't tagged or digested, this lookup always failed, so we fell back to looking at all tags of all images (below in the code).

Now, we normalize to ":latest" which should have a noticeable performance boost on nodes with many images. It's also fixed in the short-names PR but it was necessary to get this fix working as well.

if err == nil {
return ref.String(), img, nil
}
Expand Down
17 changes: 13 additions & 4 deletions pkg/specgen/generate/container_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"os"
"path/filepath"
"strings"

"github.com/containers/common/pkg/config"
"github.com/containers/podman/v2/libpod"
Expand Down Expand Up @@ -91,11 +92,19 @@ func MakeContainer(ctx context.Context, rt *libpod.Runtime, s *specgen.SpecGener
if err != nil {
return nil, err
}
imgName := s.Image
names := newImage.Names()
if len(names) > 0 {
imgName = names[0]
// If the input name changed, we could properly resolve the
// image. Otherwise, it must have been an ID where we're
// defaulting to the first name or an empty one if no names are
// 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))
}
if err := s.Validate(); err != nil {
Expand Down
19 changes: 19 additions & 0 deletions test/system/030-run.bats
Original file line number Diff line number Diff line change
Expand Up @@ -473,4 +473,23 @@ json-file | f
run_podman kill $cid
}

# Regression test for issue #8082
@test "podman run : look up correct image name" {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# 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