diff --git a/cli/command/image/list.go b/cli/command/image/list.go index cfe73c5ade..ce2238dc82 100644 --- a/cli/command/image/list.go +++ b/cli/command/image/list.go @@ -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] == ":" && len(img.RepoDigests) == 1 && img.RepoDigests[0] == "@" +} + // printAmbiguousHint prints an informational warning if the provided filter // argument is ambiguous. // diff --git a/cli/command/image/tree.go b/cli/command/image/tree.go index 804b80679e..bbcea80b13 100644 --- a/cli/command/image/tree.go +++ b/cli/command/image/tree.go @@ -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)),