Skip to content

image ls --tree: order images alphabetically - #5561

Closed
thaJeztah wants to merge 2 commits into
docker:masterfrom
thaJeztah:tree_sorting
Closed

image ls --tree: order images alphabetically#5561
thaJeztah wants to merge 2 commits into
docker:masterfrom
thaJeztah:tree_sorting

Conversation

@thaJeztah

Copy link
Copy Markdown
Member

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 lsREPOSITORY TAG IMAGE ID CREATED SIZE<none> <none> 8262a6d8c38a 7 minutes ago 13.6MBdocker-cli-dev latest f5f0547476ee 12 minutes ago 762MBnginx alpine 2140dad235c1 2 weeks ago 76.7MBalpine 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 --treeIMAGE 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.09MBdocker-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 0Balpine: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 --treeIMAGE ID DISK USAGE CONTENT SIZE USEDalpine: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 0Bdocker-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

- Description for the changelog

`docker image ls --tree` now sorts images alphabetically instead of by `CREATED` date (descending)

- A picture of a cute animal (not mandatory but encouraged)

A single image can be tagged under multiple names. While they are the
same image under the hood (same digest), we always presented these as
separate images in the list.
This patch applies the same behavior for the tree view; we can consider
having some "compact" presentation in future where we collapse these iamges
(perhaps introducing a "names" column?)
Before this patch:
$ docker pull --quiet alpine:3.20
docker.io/library/alpine:3.20
$ docker pull --quiet alpine:latest
docker.io/library/alpine:latest
$ docker image ls --tree
IMAGE ID DISK USAGE CONTENT SIZE USED
alpine:3.20
alpine:latest beefdbd8a1da 13.6MB 4.09MB
├─ 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/riscv64 80cde017a105 0B 0B
└─ linux/s390x 2b5b26e09ca2 0B 0B
With this patch applied:
$ docker image ls --tree
IMAGE ID DISK USAGE CONTENT SIZE USED
alpine:3.20 beefdbd8a1da 13.6MB 4.09MB
├─ 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/riscv64 80cde017a105 0B 0B
└─ linux/s390x 2b5b26e09ca2 0B 0B
alpine:latest beefdbd8a1da 13.6MB 4.09MB
├─ 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/riscv64 80cde017a105 0B 0B
└─ linux/s390x 2b5b26e09ca2 0B 0B
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
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>
@thaJeztahthaJeztah added status/1-design-review area/ux containerd-integration Issues and PRs related to containerd integration labels Oct 20, 2024
@thaJeztahthaJeztah added this to the 28.0.0 milestone Oct 20, 2024
@thaJeztahthaJeztah self-assigned this Oct 20, 2024
@codecov-commenter

codecov-commenter commented Oct 20, 2024

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 0% with 31 lines in your changes missing coverage. Please review.

Project coverage is 59.14%. Comparing base (062eecf) to head (be3646b).

Additional details and impacted files
@@ Coverage Diff @@## master #5561 +/- ##
==========================================
- Coverage 59.57% 59.14% -0.44% 
==========================================
Files 345 342 -3 Lines 29088 29100 +12 ==========================================
- Hits 17330 17211 -119 - Misses 10788 10917 +129 - Partials 970 972 +2 

@thaJeztahthaJeztah modified the milestones: 28.0.0, 28.0.5Mar 31, 2025
@thaJeztahthaJeztah modified the milestones: 28.1.1, 28.1.2Apr 23, 2025
@thaJeztahthaJeztah modified the milestones: 28.1.2, 28.2.0, 29.0.0May 15, 2025
@thaJeztahthaJeztah modified the milestones: 29.0.0, 29.2.0Jan 13, 2026
@thaJeztahthaJeztah modified the milestones: 29.2.0, 29.3.0Jan 26, 2026
@thaJeztahthaJeztah modified the milestones: 29.3.0, 29.4.0Mar 4, 2026
@vvoland

Copy link
Copy Markdown
Collaborator

Superseded by #6595

@vvolandvvoland closed this Apr 16, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/uxcontainerd-integrationIssues and PRs related to containerd integrationstatus/1-design-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@thaJeztah@codecov-commenter@vvoland