Skip to content

Commit 7187c78

Browse files
committed
image ls: show each tag for an image as a separate entry
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 <[email protected]>
1 parent 062eecf commit 7187c78

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

cli/command/image/tree.go

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,30 @@ func runTree(ctx context.Context, dockerCLI command.Cli, opts treeOptions) error
8282

8383
details.ContentSize = units.HumanSizeWithPrecision(float64(totalContent), 3)
8484

85-
view.images = append(view.images, topImage{
86-
Names: img.RepoTags,
87-
Details: details,
88-
Children: children,
89-
created: img.Created,
90-
})
85+
if len(img.RepoTags) == 0 {
86+
// Untagged image
87+
view.images = append(view.images, topImage{
88+
Names: img.RepoTags,
89+
Details: details,
90+
Children: children,
91+
created: img.Created,
92+
})
93+
} else {
94+
// Sort same images alphabetically to keep a consistent sort order.
95+
// We can remove this if we decide to sort the list by name, instead
96+
// of by "created" date.
97+
sort.Strings(img.RepoTags)
98+
99+
// Present images tagged under multiple names as separate images.
100+
for _, n := range img.RepoTags {
101+
view.images = append(view.images, topImage{
102+
Names: []string{n}, // Consider changing Names to be a single name for purpose of this presentation.
103+
Details: details,
104+
Children: children,
105+
created: img.Created,
106+
})
107+
}
108+
}
91109
}
92110

93111
sort.Slice(view.images, func(i, j int) bool {

0 commit comments

Comments
 (0)