MCPcopy
hub / github.com/docker/compose / Images

Method Images

pkg/compose/images.go:38–126  ·  view source on GitHub ↗
(ctx context.Context, projectName string, options api.ImagesOptions)

Source from the content-addressed store, hash-verified

36)
37
38func (s *composeService) Images(ctx context.Context, projectName string, options api.ImagesOptions) (map[string]api.ImageSummary, error) {
39 projectName = strings.ToLower(projectName)
40 allContainers, err := s.apiClient().ContainerList(ctx, client.ContainerListOptions{
41 All: true,
42 Filters: projectFilter(projectName),
43 })
44 if err != nil {
45 return nil, err
46 }
47 var containers []container.Summary
48 if len(options.Services) > 0 {
49 // filter service containers
50 for _, c := range allContainers.Items {
51 if slices.Contains(options.Services, c.Labels[api.ServiceLabel]) {
52 containers = append(containers, c)
53 }
54 }
55 } else {
56 containers = allContainers.Items
57 }
58
59 // The daemon validates the platform field in ImageInspect against the
60 // negotiated API version from the request path, not the server's own max version.
61 version, err := s.RuntimeAPIVersion(ctx)
62 if err != nil {
63 return nil, err
64 }
65 withPlatform := versions.GreaterThanOrEqualTo(version, apiVersion149)
66
67 summary := map[string]api.ImageSummary{}
68 var mux sync.Mutex
69 eg, ctx := errgroup.WithContext(ctx)
70 for _, c := range containers {
71 eg.Go(func() error {
72 image, err := s.apiClient().ImageInspect(ctx, c.Image)
73 if err != nil {
74 return err
75 }
76 id := image.ID // platform-specific image ID can't be combined with image tag, see https://github.com/moby/moby/issues/49995
77
78 if withPlatform && c.ImageManifestDescriptor != nil && c.ImageManifestDescriptor.Platform != nil {
79 image, err = s.apiClient().ImageInspect(ctx, c.Image, client.ImageInspectWithPlatform(c.ImageManifestDescriptor.Platform))
80 if err != nil {
81 return err
82 }
83 }
84
85 var repository, tag string
86 ref, err := reference.ParseDockerRef(c.Image)
87 if err == nil {
88 // ParseDockerRef will reject a local image ID
89 repository = reference.FamiliarName(ref)
90 if tagged, ok := ref.(reference.Tagged); ok {
91 tag = tagged.Tag()
92 }
93 }
94
95 var created *time.Time

Callers

nothing calls this directly

Calls 8

apiClientMethod · 0.95
RuntimeAPIVersionMethod · 0.95
projectFilterFunction · 0.85
WaitMethod · 0.65
ContainerListMethod · 0.45
ImageInspectMethod · 0.45
LockMethod · 0.45

Tested by

no test coverage detected