DockerCLI/cli/command/image
Sebastiaan van Stijn be3646b87c
image ls --tree: order images alphabetically
The tree output currently uses the same sort order as the existing
non-tree output, and orders the images by "created" time in descending
order;

    docker image ls
    REPOSITORY       TAG       IMAGE ID       CREATED          SIZE
    <none>           <none>    8262a6d8c38a   7 minutes ago    13.6MB
    docker-cli-dev   latest    f5f0547476ee   12 minutes ago   762MB
    nginx            alpine    2140dad235c1   2 weeks ago      76.7MB
    alpine           latest    beefdbd8a1da   6 weeks ago      24.2MB

However, the `--tree` view does not have a `CREATED` column, which makes
the output order seem "random". With the tree view being more verbose,
it may also be harder to find back images in the list when they're not sorted
in an easy to discover way.

This patch changes the sort order:

- alphabetically (natural sort) for tagged images
- untagged images are sorted last, as they're likely less relevant
  to the user, and should not be "polluting" th top of the list.
- if multiple untagged images exist, they are sorted by created
  date (descending) to get a stable order.

Before this patch:

    $ docker image ls --tree

    IMAGE                   ID             DISK USAGE   CONTENT SIZE   USED
    <untagged>              20ad73eca911       13.6MB         4.09MB    ✔
    └─ linux/arm64          1ab6fc68586e       13.6MB         4.09MB    ✔

    <untagged>              b3e87f642f5c       13.6MB         4.09MB
    └─ linux/arm64          1ab6fc68586e       13.6MB         4.09MB

    docker-cli-dev:latest   f5f0547476ee        762MB          179MB    ✔
    └─ linux/arm64          18ca7881145d        762MB          179MB    ✔

    nginx:alpine            2140dad235c1       76.7MB         21.5MB
    ├─ linux/arm64/v8       d1f949a77b81       76.7MB         21.5MB
    ├─ linux/amd64          ae136e431e76           0B             0B
    ├─ linux/arm/v6         ae1ee4b63c14           0B             0B
    ├─ linux/arm/v7         20ad73eca911           0B             0B
    ├─ linux/386            1e69bfb21757           0B             0B
    ├─ linux/ppc64le        7fef8bcf8b6c           0B             0B
    └─ linux/s390x          8c310bf29cfa           0B             0B

    alpine:latest           beefdbd8a1da       24.2MB         7.46MB
    ├─ linux/riscv64        80cde017a105       10.6MB         3.37MB
    ├─ linux/arm64/v8       9cee2b382fe2       13.6MB         4.09MB
    ├─ linux/amd64          33735bd63cf8           0B             0B
    ├─ linux/arm/v6         50f635c8b04d           0B             0B
    ├─ linux/arm/v7         f2f82d424957           0B             0B
    ├─ linux/386            b3e87f642f5c           0B             0B
    ├─ linux/ppc64le        c7a6800e3dc5           0B             0B
    └─ linux/s390x          2b5b26e09ca2           0B             0B

With this patch:

    $ docker image ls --tree

    IMAGE                   ID             DISK USAGE   CONTENT SIZE   USED
    alpine:latest           beefdbd8a1da       24.2MB         7.46MB
    ├─ linux/riscv64        80cde017a105       10.6MB         3.37MB
    ├─ linux/arm64/v8       9cee2b382fe2       13.6MB         4.09MB
    ├─ linux/amd64          33735bd63cf8           0B             0B
    ├─ linux/arm/v6         50f635c8b04d           0B             0B
    ├─ linux/arm/v7         f2f82d424957           0B             0B
    ├─ linux/386            b3e87f642f5c           0B             0B
    ├─ linux/ppc64le        c7a6800e3dc5           0B             0B
    └─ linux/s390x          2b5b26e09ca2           0B             0B

    docker-cli-dev:latest   f5f0547476ee        762MB          179MB    ✔
    └─ linux/arm64          18ca7881145d        762MB          179MB    ✔

    nginx:alpine            2140dad235c1       76.7MB         21.5MB
    ├─ linux/arm64/v8       d1f949a77b81       76.7MB         21.5MB
    ├─ linux/amd64          ae136e431e76           0B             0B
    ├─ linux/arm/v6         ae1ee4b63c14           0B             0B
    ├─ linux/arm/v7         20ad73eca911           0B             0B
    ├─ linux/386            1e69bfb21757           0B             0B
    ├─ linux/ppc64le        7fef8bcf8b6c           0B             0B
    └─ linux/s390x          8c310bf29cfa           0B             0B

    <untagged>              20ad73eca911       13.6MB         4.09MB    ✔
    └─ linux/arm64          1ab6fc68586e       13.6MB         4.09MB    ✔

    <untagged>              b3e87f642f5c       13.6MB         4.09MB
    └─ linux/arm64          1ab6fc68586e       13.6MB         4.09MB

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-10-20 23:54:57 +02:00
..
build cli/command/image/build: fix nosec comment 2024-06-10 21:19:32 +02:00
testdata image/history: Add `--platform` flag 2024-10-10 17:00:43 +02:00
build.go cli/command/image: add shell completion for --platform flags 2024-10-08 13:15:28 +02:00
build_test.go test spring-cleaning 2024-07-04 01:35:12 +02:00
client_test.go vendor: github.com/docker/docker 164cae56ed95 (master, v-next) 2024-09-24 16:30:30 +02:00
cmd.go Adopt Cobra completion v2 to support completion by CLI plugins 2022-05-12 12:59:10 +02:00
formatter_history.go linting: address else/if/elseif statements found by gocritic 2023-11-20 16:02:16 +01:00
formatter_history_test.go golangci-lint: enable dupword linter 2023-11-20 16:02:18 +01:00
history.go image/history: Add `--platform` flag 2024-10-10 17:00:43 +02:00
history_test.go image/history: Add `--platform` flag 2024-10-10 17:00:43 +02:00
import.go cli/command/image: add shell completion for --platform flags 2024-10-08 13:15:28 +02:00
import_test.go cli: improve argument validation output 2024-07-05 03:35:14 +02:00
inspect.go Enable completion for 'image' sub commands 2024-07-03 17:00:40 +01:00
inspect_test.go cli: improve argument validation output 2024-07-05 03:35:14 +02:00
list.go image/list: Add `--tree` flag 2024-08-16 15:09:51 +02:00
list_test.go cli: improve argument validation output 2024-07-05 03:35:14 +02:00
load.go image/load: Add `--platform` 2024-10-10 16:35:07 +02:00
load_test.go image/load: Add `--platform` 2024-10-10 16:35:07 +02:00
prune.go chore: remove backticks and resolve linting issues 2024-04-02 15:54:29 +02:00
prune_test.go cli: improve argument validation output 2024-07-05 03:35:14 +02:00
pull.go cli/command/image: add shell completion for --platform flags 2024-10-08 13:15:28 +02:00
pull_test.go cli: improve argument validation output 2024-07-05 03:35:14 +02:00
push.go cli/command/image: add shell completion for --platform flags 2024-10-08 13:15:28 +02:00
push_test.go cli: improve argument validation output 2024-07-05 03:35:14 +02:00
remove.go Enable completion for 'image' sub commands 2024-07-03 17:00:40 +01:00
remove_test.go cli: improve argument validation output 2024-07-05 03:35:14 +02:00
save.go image/save: Add `--platform` 2024-10-10 16:35:03 +02:00
save_test.go image/save: Add `--platform` 2024-10-10 16:35:03 +02:00
tag.go Plumb contexts through commands 2023-12-12 22:30:16 +01:00
tag_test.go cli: improve argument validation output 2024-07-05 03:35:14 +02:00
tree.go image ls --tree: order images alphabetically 2024-10-20 23:54:57 +02:00
trust.go Removed all mentions of "please" from docs and messages 2024-06-11 16:53:40 +02:00
trust_test.go replace uses of deprecated env.Patch() 2022-09-22 17:28:07 +02:00