Merge pull request #5924 from thaJeztah/hide_untagged

docker images --tree: hide both untagged and dangling images by default
This commit is contained in:
Paweł Gronowski 2025-04-11 13:14:59 +00:00 committed by GitHub
commit 07b203e2f2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 0 deletions

View File

@ -135,6 +135,14 @@ func runImages(ctx context.Context, dockerCLI command.Cli, options imagesOptions
return nil
}
// isDangling is a copy of [formatter.isDangling].
func isDangling(img image.Summary) bool {
if len(img.RepoTags) == 0 && len(img.RepoDigests) == 0 {
return true
}
return len(img.RepoTags) == 1 && img.RepoTags[0] == "<none>:<none>" && len(img.RepoDigests) == 1 && img.RepoDigests[0] == "<none>@<none>"
}
// printAmbiguousHint prints an informational warning if the provided filter
// argument is ambiguous.
//

View File

@ -1,8 +1,12 @@
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
//go:build go1.22
package image
import (
"context"
"fmt"
"slices"
"sort"
"strings"
@ -38,6 +42,9 @@ func runTree(ctx context.Context, dockerCLI command.Cli, opts treeOptions) error
if err != nil {
return err
}
if !opts.all {
images = slices.DeleteFunc(images, isDangling)
}
view := treeView{
images: make([]topImage, 0, len(images)),