Skip to content

Commit

Permalink
fix(docker): getting an image by ID or a name with tag (fanal#425)
Browse files Browse the repository at this point in the history
  • Loading branch information
afdesk authored Mar 17, 2022
1 parent 483697b commit e913433
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions image/daemon/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,17 @@ func DockerImage(ref name.Reference) (Image, func(), error) {
}
}()

imageID := ref.String()
// <image_name>:<tag> pattern like "alpine:3.15"
// or
// <image_name>@<digest> pattern like "alpine@sha256:21a3deaa0d32a8057914f36584b5288d2e5ecc984380bc0118285c70fa8c9300"
imageID := ref.Name()
inspect, _, err := c.ImageInspectWithRaw(context.Background(), imageID)
if err != nil {
return nil, cleanup, xerrors.Errorf("unable to inspect the image (%s): %w", imageID, err)
imageID = ref.String() // <image_id> pattern like `5ac716b05a9c`
inspect, _, err = c.ImageInspectWithRaw(context.Background(), imageID)
if err != nil {
return nil, cleanup, xerrors.Errorf("unable to inspect the image (%s): %w", imageID, err)
}
}

history, err := c.ImageHistory(context.Background(), imageID)
Expand Down

0 comments on commit e913433

Please sign in to comment.