{"id":"c41bd4cddd26283a","repo":"docker/cli","slug":"cowardly-refusing-to-save-to-a-terminal-use-the-c41bd4","errorCode":null,"errorMessage":"cowardly refusing to save to a terminal. Use the -o flag or redirect","messagePattern":"cowardly refusing to save to a terminal\\. Use the -o flag or redirect","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/image/save.go","lineNumber":73,"sourceCode":"func runSave(ctx context.Context, dockerCLI command.Cli, opts saveOptions) error {\n\tvar options []client.ImageSaveOption\n\n\tplatformList := []ocispec.Platform{}\n\tfor _, p := range opts.platform {\n\t\tpp, err := platforms.Parse(p)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"invalid platform: %w\", err)\n\t\t}\n\t\tplatformList = append(platformList, pp)\n\t}\n\tif len(platformList) > 0 {\n\t\toptions = append(options, client.ImageSaveWithPlatforms(platformList...))\n\t}\n\n\tvar output io.Writer\n\tif opts.output == \"\" {\n\t\tif dockerCLI.Out().IsTerminal() {\n\t\t\treturn errors.New(\"cowardly refusing to save to a terminal. Use the -o flag or redirect\")\n\t\t}\n\t\toutput = dockerCLI.Out()\n\t} else {\n\t\twriter, err := atomicwriter.New(opts.output, 0o600)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to save image: %w\", err)\n\t\t}\n\t\tdefer writer.Close()\n\t\toutput = writer\n\t}\n\n\tresponseBody, err := dockerCLI.Client().ImageSave(ctx, opts.images, options...)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer responseBody.Close()\n\n\t_, err = io.Copy(output, responseBody)","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/docker/cli/blob/e9452d6e785f6e365712b9d71bd7517591773c86/cli/command/image/save.go#L55-L91","documentation":"docker image save writes a binary tar archive to stdout when no --output/-o flag is given. In cli/command/image/save.go:71-73, if opts.output is empty and stdout is a terminal (dockerCLI.Out().IsTerminal()), the CLI refuses to dump raw tar bytes onto the TTY — which would spew garbage and can corrupt the terminal state. The 'cowardly refusing' guard forces you to name a file or redirect.","triggerScenarios":"Running `docker save myimage` (or docker image save) in an interactive shell without -o and without redirecting/piping stdout, so stdout is a TTY.","commonSituations":"Forgetting -o on an interactive save; expecting docker save to take a filename positionally (all positional args are image names, not an output path); wrapper scripts that lose the intended redirection.","solutions":["Use the output flag: docker save -o myimage.tar myimage:latest","Or redirect stdout: docker save myimage:latest > myimage.tar","Or pipe to a consumer: docker save myimage | gzip > myimage.tar.gz"],"exampleFix":"# before\ndocker save myimage:latest        # stdout is a terminal -> refused\n# after\ndocker save -o myimage.tar myimage:latest\n# or\ndocker save myimage:latest > myimage.tar","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":["docker-cli","image-save","stdout","tty","tar"],"analyzedSha":"e9452d6e785f6e365712b9d71bd7517591773c86","analyzedAt":"2026-08-01T07:09:22.474Z","schemaVersion":2}