Skip to content

Commit ea1c26d

Browse files
ndeloofglours
authored andcommitted
restore ContainerName in images --json
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 9a5fa05 commit ea1c26d

1 file changed

Lines changed: 27 additions & 4 deletions

File tree

cmd/compose/images.go

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,35 @@ func runImages(ctx context.Context, dockerCli command.Cli, backend api.Service,
8888
return nil
8989
}
9090
if opts.Format == "json" {
91+
92+
type img struct {
93+
ID string `json:"ID"`
94+
ContainerName string `json:"ContainerName"`
95+
Repository string `json:"Repository"`
96+
Tag string `json:"Tag"`
97+
Platform string `json:"Platform"`
98+
Size int64 `json:"Size"`
99+
LastTagTime time.Time `json:"LastTagTime"`
100+
}
91101
// Convert map to slice
92-
var imageList []api.ImageSummary
93-
for _, img := range images {
94-
imageList = append(imageList, img)
102+
var imageList []img
103+
for ctr, i := range images {
104+
imageList = append(imageList, img{
105+
ContainerName: ctr,
106+
ID: i.ID,
107+
Repository: i.Repository,
108+
Tag: i.Tag,
109+
Platform: platforms.Format(i.Platform),
110+
Size: i.Size,
111+
LastTagTime: i.LastTagTime,
112+
})
95113
}
96-
return formatter.Print(imageList, opts.Format, dockerCli.Out(), nil)
114+
json, err := formatter.ToJSON(imageList, "", "")
115+
if err != nil {
116+
return err
117+
}
118+
_, err = fmt.Fprintln(dockerCli.Out(), json)
119+
return err
97120
}
98121

99122
return formatter.Print(images, opts.Format, dockerCli.Out(),

0 commit comments

Comments
 (0)