From ea1c26d22a7781738cabf6007071d5957367786b Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Mon, 16 Jun 2025 08:16:30 +0200 Subject: [PATCH] restore ContainerName in images --json Signed-off-by: Nicolas De Loof --- cmd/compose/images.go | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/cmd/compose/images.go b/cmd/compose/images.go index afc22feff..5544204c8 100644 --- a/cmd/compose/images.go +++ b/cmd/compose/images.go @@ -88,12 +88,35 @@ func runImages(ctx context.Context, dockerCli command.Cli, backend api.Service, return nil } if opts.Format == "json" { - // Convert map to slice - var imageList []api.ImageSummary - for _, img := range images { - imageList = append(imageList, img) + + type img struct { + ID string `json:"ID"` + ContainerName string `json:"ContainerName"` + Repository string `json:"Repository"` + Tag string `json:"Tag"` + Platform string `json:"Platform"` + Size int64 `json:"Size"` + LastTagTime time.Time `json:"LastTagTime"` } - return formatter.Print(imageList, opts.Format, dockerCli.Out(), nil) + // Convert map to slice + var imageList []img + for ctr, i := range images { + imageList = append(imageList, img{ + ContainerName: ctr, + ID: i.ID, + Repository: i.Repository, + Tag: i.Tag, + Platform: platforms.Format(i.Platform), + Size: i.Size, + LastTagTime: i.LastTagTime, + }) + } + json, err := formatter.ToJSON(imageList, "", "") + if err != nil { + return err + } + _, err = fmt.Fprintln(dockerCli.Out(), json) + return err } return formatter.Print(images, opts.Format, dockerCli.Out(),