diff --git a/cli/command/image/tree.go b/cli/command/image/tree.go index 3efb24164439..e06bd7877b39 100644 --- a/cli/command/image/tree.go +++ b/cli/command/image/tree.go @@ -32,7 +32,7 @@ func runTree(ctx context.Context, dockerCLI command.Cli, opts treeOptions) error return err } - var view []topImage + view := make([]topImage, 0, len(images)) for _, img := range images { details := imageDetails{ ID: img.ID, @@ -40,7 +40,7 @@ func runTree(ctx context.Context, dockerCLI command.Cli, opts treeOptions) error Used: img.Containers > 0, } - var children []subImage + children := make([]subImage, 0, len(img.Manifests)) for _, im := range img.Manifests { if im.Kind != imagetypes.ImageManifestKindImage { continue @@ -62,13 +62,11 @@ func runTree(ctx context.Context, dockerCLI command.Cli, opts treeOptions) error children = append(children, sub) } - for _, tag := range img.RepoTags { - view = append(view, topImage{ - Name: tag, - Details: details, - Children: children, - }) - } + view = append(view, topImage{ + Names: img.RepoTags, + Details: details, + Children: children, + }) } return printImageTree(dockerCLI, view) @@ -81,7 +79,7 @@ type imageDetails struct { } type topImage struct { - Name string + Names []string Details imageDetails Children []subImage } @@ -115,8 +113,10 @@ func printImageTree(dockerCLI command.Cli, images []topImage) error { maxImageName := len(headers[0].Title) for _, img := range images { - if len(img.Name) > maxImageName { - maxImageName = len(img.Name) + for _, name := range img.Names { + if len(name) > maxImageName { + maxImageName = len(name) + } } for _, sub := range img.Children { if len(sub.Platform) > maxImageName { @@ -170,7 +170,12 @@ func printImageTree(dockerCLI command.Cli, images []topImage) error { // Print images for _, img := range images { - fmt.Fprint(out, headers[0].Print(topNameColor, img.Name)) + for idx, name := range img.Names { + fmt.Fprint(out, headers[0].Print(topNameColor, name)) + if idx != len(img.Names)-1 { + fmt.Fprintln(out, "") + } + } fmt.Fprint(out, strings.Repeat(" ", spacing)) printDetails(normalColor, img.Details)