MCPcopy Create free account
hub / github.com/containerd/nerdctl / List

Function List

pkg/cmd/image/list.go:73–114  ·  view source on GitHub ↗

List queries containerd client to get image list and only returns those matching given filters. Supported filters: - before= [: ]: Images created before given image (exclusive) - since= [: ]: Images created after given image (exclusive) - label= [= ]: Matches images ba

(ctx context.Context, client *containerd.Client, filters, nameAndRefFilter []string)

Source from the content-addressed store, hash-verified

71// while the remaining filters are only applied after getting images from containerd,
72// which means that having nameAndRefFilter may speed up the process if there are a lot of images in containerd.
73func List(ctx context.Context, client *containerd.Client, filters, nameAndRefFilter []string) ([]images.Image, error) {
74 var imageStore = client.ImageService()
75 imageList, err := imageStore.List(ctx, nameAndRefFilter...)
76 if err != nil {
77 return nil, err
78 }
79 if len(filters) > 0 {
80 f, err := imgutil.ParseFilters(filters)
81 if err != nil {
82 return nil, err
83 }
84
85 filters := []imgutil.Filter{}
86 if f.Dangling != nil && *f.Dangling {
87 filters = append(filters, imgutil.FilterDanglingImages())
88 } else if f.Dangling != nil {
89 filters = append(filters, imgutil.FilterTaggedImages())
90 }
91
92 if len(f.Labels) > 0 {
93 filters = append(filters, imgutil.FilterByLabel(ctx, client, f.Labels))
94 }
95
96 if len(f.Reference) > 0 {
97 filters = append(filters, imgutil.FilterByReference(f.Reference))
98 }
99
100 if len(f.Before) > 0 || len(f.Since) > 0 {
101 filters = append(filters, imgutil.FilterByCreatedAt(ctx, client, f.Before, f.Since))
102 }
103
104 imageList, err = imgutil.ApplyFilters(imageList, filters...)
105 if err != nil {
106 return []images.Image{}, err
107 }
108 }
109
110 sort.Slice(imageList, func(i, j int) bool {
111 return imageList[i].CreatedAt.After(imageList[j].CreatedAt)
112 })
113 return imageList, nil
114}
115
116type imagePrintable struct {
117 // TODO: "Containers"

Callers 1

ListCommandHandlerFunction · 0.70

Calls 8

ParseFiltersFunction · 0.92
FilterDanglingImagesFunction · 0.92
FilterTaggedImagesFunction · 0.92
FilterByLabelFunction · 0.92
FilterByReferenceFunction · 0.92
FilterByCreatedAtFunction · 0.92
ApplyFiltersFunction · 0.92
ListMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…