- 
                Notifications
    You must be signed in to change notification settings 
- Fork 2.1k
          image/list: Hide untagged images without --all
          #6574
        
          New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,10 +1,13 @@ | ||
| //go:build go1.23 | ||
|  | ||
| package image | ||
|  | ||
| import ( | ||
| "context" | ||
| "errors" | ||
| "fmt" | ||
| "io" | ||
| "slices" | ||
|  | ||
| "github.com/docker/cli/cli" | ||
| "github.com/docker/cli/cli/command" | ||
|  | @@ -79,6 +82,7 @@ func newListCommand(dockerCLI command.Cli) *cobra.Command { | |
| return &cmd | ||
| } | ||
|  | ||
| //nolint:gocyclo | ||
| func runImages(ctx context.Context, dockerCLI command.Cli, options imagesOptions) error { | ||
| filters := options.filter.Value() | ||
| if options.matchName != "" { | ||
|  | @@ -98,20 +102,32 @@ func runImages(ctx context.Context, dockerCLI command.Cli, options imagesOptions | |
| if options.format != "" { | ||
| return errors.New("--format is not yet supported with --tree") | ||
| } | ||
| } | ||
|  | ||
| return runTree(ctx, dockerCLI, treeOptions{ | ||
| all: options.all, | ||
| filters: filters, | ||
| }) | ||
| listOpts := client.ImageListOptions{ | ||
| All: options.all, | ||
| Filters: filters, | ||
| Manifests: options.tree, | ||
| } | ||
|  | ||
| images, err := dockerCLI.Client().ImageList(ctx, client.ImageListOptions{ | ||
| All: options.all, | ||
| Filters: filters, | ||
| }) | ||
| res, err := dockerCLI.Client().ImageList(ctx, listOpts) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| images := res.Items | ||
| if !options.all { | ||
| if _, ok := filters["dangling"]; ok { | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not 100% sure about this, but I think it makes sense to NOT manipulate the dangling images if  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not at my computer to test, but this means that filtering for dangling images won't produce a result unless --all is also passed? Or is this just the optimization to not process them? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, without this change  | ||
| images = slices.DeleteFunc(images, isDangling) | ||
| } | ||
| } | ||
|  | ||
| if options.tree { | ||
| return runTree(ctx, dockerCLI, treeOptions{ | ||
| images: images, | ||
| all: options.all, | ||
| filters: filters, | ||
| }) | ||
| } | ||
|  | ||
| format := options.format | ||
| if len(format) == 0 { | ||
|  | @@ -130,10 +146,10 @@ func runImages(ctx context.Context, dockerCLI command.Cli, options imagesOptions | |
| }, | ||
| Digest: options.showDigests, | ||
| } | ||
| if err := formatter.ImageWrite(imageCtx, images.Items); err != nil { | ||
| if err := formatter.ImageWrite(imageCtx, images); err != nil { | ||
| return err | ||
| } | ||
| if options.matchName != "" && len(images.Items) == 0 && options.calledAs == "images" { | ||
| if options.matchName != "" && len(images) == 0 && options.calledAs == "images" { | ||
| printAmbiguousHint(dockerCLI.Err(), options.matchName) | ||
| } | ||
| return nil | ||
|  | ||
Uh oh!
There was an error while loading. Please reload this page.