diff options
author | Valentin Rothberg <rothberg@redhat.com> | 2020-10-21 15:25:17 +0200 |
---|---|---|
committer | Valentin Rothberg <rothberg@redhat.com> | 2020-10-21 16:51:09 +0200 |
commit | 410fa53f89b1c408ce57318bb054b4229ad845d5 (patch) | |
tree | 4cb1848771aeedd3b5c0d8d9b3711d9925d3c06f /pkg/specgen/generate/container_create.go | |
parent | 9d9c58ba64a59fc24d6807f495559ac2ec86b6e8 (diff) | |
download | podman-410fa53f89b1c408ce57318bb054b4229ad845d5.tar.gz podman-410fa53f89b1c408ce57318bb054b4229ad845d5.tar.bz2 podman-410fa53f89b1c408ce57318bb054b4229ad845d5.zip |
container create: record correct image name
Record the correct image name when creating a container by using the
resolved image name if present. Otherwise, default to using the first
available name or an empty string in which case the image must have been
referenced by ID.
Fixes: #8082
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'pkg/specgen/generate/container_create.go')
-rw-r--r-- | pkg/specgen/generate/container_create.go | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/pkg/specgen/generate/container_create.go b/pkg/specgen/generate/container_create.go index 105e36bc6..f051537de 100644 --- a/pkg/specgen/generate/container_create.go +++ b/pkg/specgen/generate/container_create.go @@ -4,6 +4,7 @@ import ( "context" "os" "path/filepath" + "strings" "github.com/containers/common/pkg/config" "github.com/containers/podman/v2/libpod" @@ -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 { |