From 324cc5d30f4e6a301b166365ca671f9d0fd605b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Fri, 16 Aug 2024 11:32:37 +0200 Subject: [PATCH] list/tree: Sort by created date MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Paweł Gronowski (cherry picked from commit b1a08f78417849ae4d51049f1102e3b1789bac35) Signed-off-by: Paweł Gronowski --- cli/command/image/tree.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cli/command/image/tree.go b/cli/command/image/tree.go index 03930b2f11..868c68582b 100644 --- a/cli/command/image/tree.go +++ b/cli/command/image/tree.go @@ -3,6 +3,7 @@ package image import ( "context" "fmt" + "sort" "strings" "unicode/utf8" @@ -68,13 +69,19 @@ func runTree(ctx context.Context, dockerCLI command.Cli, opts treeOptions) error } details.ContentSize = units.HumanSizeWithPrecision(float64(totalContent), 3) + view = append(view, topImage{ Names: img.RepoTags, Details: details, Children: children, + created: img.Created, }) } + sort.Slice(view, func(i, j int) bool { + return view[i].created > view[j].created + }) + return printImageTree(dockerCLI, view) } @@ -89,6 +96,8 @@ type topImage struct { Names []string Details imageDetails Children []subImage + + created int64 } type subImage struct {