MCPcopy Index your code
hub / github.com/docker/cli / runRemove

Function runRemove

cli/command/image/remove.go:62–106  ·  view source on GitHub ↗
(ctx context.Context, dockerCLI command.Cli, opts removeOptions, images []string)

Source from the content-addressed store, hash-verified

60}
61
62func runRemove(ctx context.Context, dockerCLI command.Cli, opts removeOptions, images []string) error {
63 apiClient := dockerCLI.Client()
64
65 options := client.ImageRemoveOptions{
66 Force: opts.force,
67 PruneChildren: !opts.noPrune,
68 }
69
70 for _, v := range opts.platforms {
71 p, err := platforms.Parse(v)
72 if err != nil {
73 return err
74 }
75 options.Platforms = append(options.Platforms, p)
76 }
77
78 // TODO(thaJeztah): this logic can likely be simplified: do we want to print "not found" errors at all when using "force"?
79 fatalErr := false
80 var errs []error
81 for _, img := range images {
82 res, err := apiClient.ImageRemove(ctx, img, options)
83 if err != nil {
84 if !errdefs.IsNotFound(err) {
85 fatalErr = true
86 }
87 errs = append(errs, err)
88 } else {
89 for _, del := range res.Items {
90 if del.Deleted != "" {
91 _, _ = fmt.Fprintln(dockerCLI.Out(), "Deleted:", del.Deleted)
92 } else {
93 _, _ = fmt.Fprintln(dockerCLI.Out(), "Untagged:", del.Untagged)
94 }
95 }
96 }
97 }
98
99 if err := errors.Join(errs...); err != nil {
100 if !opts.force || fatalErr {
101 return err
102 }
103 _, _ = fmt.Fprintln(dockerCLI.Err(), err)
104 }
105 return nil
106}

Callers 1

newRemoveCommandFunction · 0.70

Calls 4

ImageRemoveMethod · 0.80
ClientMethod · 0.65
OutMethod · 0.65
ErrMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…