diff --git a/cli/command/image/tree.go b/cli/command/image/tree.go index ec4ef7b4e4b4..c119428543f9 100644 --- a/cli/command/image/tree.go +++ b/cli/command/image/tree.go @@ -82,12 +82,25 @@ func runTree(ctx context.Context, dockerCLI command.Cli, opts treeOptions) error details.ContentSize = units.HumanSizeWithPrecision(float64(totalContent), 3) - view.images = append(view.images, topImage{ - Names: img.RepoTags, - Details: details, - Children: children, - created: img.Created, - }) + if len(img.RepoTags) == 0 { + // Untagged image + view.images = append(view.images, topImage{ + Names: img.RepoTags, + Details: details, + Children: children, + created: img.Created, + }) + } else { + // Present images tagged under multiple names as separate images. + for _, n := range img.RepoTags { + view.images = append(view.images, topImage{ + Names: []string{n}, // Consider changing Names to be a single name for purpose of this presentation. + Details: details, + Children: children, + created: img.Created, + }) + } + } } sort.Slice(view.images, func(i, j int) bool {