Skip to content

Commit 07b203e

Browse files
authored
Merge pull request #5924 from thaJeztah/hide_untagged
docker images --tree: hide both untagged and dangling images by default
2 parents c718d3f + f18e239 commit 07b203e

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

cli/command/image/list.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,14 @@ func runImages(ctx context.Context, dockerCLI command.Cli, options imagesOptions
135135
return nil
136136
}
137137

138+
// isDangling is a copy of [formatter.isDangling].
139+
func isDangling(img image.Summary) bool {
140+
if len(img.RepoTags) == 0 && len(img.RepoDigests) == 0 {
141+
return true
142+
}
143+
return len(img.RepoTags) == 1 && img.RepoTags[0] == "<none>:<none>" && len(img.RepoDigests) == 1 && img.RepoDigests[0] == "<none>@<none>"
144+
}
145+
138146
// printAmbiguousHint prints an informational warning if the provided filter
139147
// argument is ambiguous.
140148
//

cli/command/image/tree.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
2+
//go:build go1.22
3+
14
package image
25

36
import (
47
"context"
58
"fmt"
9+
"slices"
610
"sort"
711
"strings"
812

@@ -38,6 +42,9 @@ func runTree(ctx context.Context, dockerCLI command.Cli, opts treeOptions) error
3842
if err != nil {
3943
return err
4044
}
45+
if !opts.all {
46+
images = slices.DeleteFunc(images, isDangling)
47+
}
4148

4249
view := treeView{
4350
images: make([]topImage, 0, len(images)),

0 commit comments

Comments
 (0)