diff --git a/libimage/filters.go b/libimage/filters.go index 441011edd..ff50321b7 100644 --- a/libimage/filters.go +++ b/libimage/filters.go @@ -178,7 +178,7 @@ func (r *Runtime) compileImageFilters(ctx context.Context, options *ListImagesOp filter = filterManifest(ctx, manifest) case "reference": - filter = filterReferences(value) + filter = filterReferences(r, value) case "until": until, err := r.until(value) @@ -268,8 +268,15 @@ func filterManifest(ctx context.Context, value bool) filterFunc { } // filterReferences creates a reference filter for matching the specified value. -func filterReferences(value string) filterFunc { +func filterReferences(r *Runtime, value string) filterFunc { + lookedUp, _, _ := r.LookupImage(value, nil) return func(img *Image) (bool, error) { + if lookedUp != nil { + if lookedUp.ID() == img.ID() { + return true, nil + } + } + refs, err := img.NamesReferences() if err != nil { return false, err @@ -306,6 +313,7 @@ func filterReferences(value string) filterFunc { } } } + return false, nil } } diff --git a/libimage/filters_test.go b/libimage/filters_test.go index e912056fa..12091b130 100644 --- a/libimage/filters_test.go +++ b/libimage/filters_test.go @@ -62,6 +62,7 @@ func TestFilterReference(t *testing.T) { {"quay.io/libpod/*", 2}, {"busybox", 1}, {"alpine", 1}, + {"alpine@" + alpine.Digest().String(), 1}, } { listOptions := &ListImagesOptions{ Filters: []string{"reference=" + test.filter},