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

Function runSave

cli/command/image/save.go:55–93  ·  view source on GitHub ↗

runSave performs a save against the engine based on the specified options

(ctx context.Context, dockerCLI command.Cli, opts saveOptions)

Source from the content-addressed store, hash-verified

53
54// runSave performs a save against the engine based on the specified options
55func runSave(ctx context.Context, dockerCLI command.Cli, opts saveOptions) error {
56 var options []client.ImageSaveOption
57
58 platformList := []ocispec.Platform{}
59 for _, p := range opts.platform {
60 pp, err := platforms.Parse(p)
61 if err != nil {
62 return fmt.Errorf("invalid platform: %w", err)
63 }
64 platformList = append(platformList, pp)
65 }
66 if len(platformList) > 0 {
67 options = append(options, client.ImageSaveWithPlatforms(platformList...))
68 }
69
70 var output io.Writer
71 if opts.output == "" {
72 if dockerCLI.Out().IsTerminal() {
73 return errors.New("cowardly refusing to save to a terminal. Use the -o flag or redirect")
74 }
75 output = dockerCLI.Out()
76 } else {
77 writer, err := atomicwriter.New(opts.output, 0o600)
78 if err != nil {
79 return fmt.Errorf("failed to save image: %w", err)
80 }
81 defer writer.Close()
82 output = writer
83 }
84
85 responseBody, err := dockerCLI.Client().ImageSave(ctx, opts.images, options...)
86 if err != nil {
87 return err
88 }
89 defer responseBody.Close()
90
91 _, err = io.Copy(output, responseBody)
92 return err
93}

Callers 1

newSaveCommandFunction · 0.85

Calls 5

ImageSaveMethod · 0.80
OutMethod · 0.65
ClientMethod · 0.65
IsTerminalMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…