{"record":{"id":"72fd0e6678261c20","repo":"docker/cli","slug":"cowardly-refusing-to-save-to-a-terminal-use-the","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":"warning","filePath":"cli/command/container/export.go","lineNumber":52,"sourceCode":"\t\tAnnotations: map[string]string{\n\t\t\t\"aliases\": \"docker container export, docker export\",\n\t\t},\n\t\tValidArgsFunction:     completion.ContainerNames(dockerCLI, true),\n\t\tDisableFlagsInUseLine: true,\n\t}\n\n\tflags := cmd.Flags()\n\n\tflags.StringVarP(&opts.output, \"output\", \"o\", \"\", \"Write to a file, instead of STDOUT\")\n\n\treturn cmd\n}\n\nfunc runExport(ctx context.Context, dockerCLI command.Cli, opts exportOptions) error {\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 export container: %w\", err)\n\t\t}\n\t\tdefer writer.Close()\n\t\toutput = writer\n\t}\n\n\tresponseBody, err := dockerCLI.Client().ContainerExport(ctx, opts.container, client.ContainerExportOptions{})\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer responseBody.Close()\n\n\t_, err = io.Copy(output, responseBody)","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/container/export.go#L34-L70","documentation":"Returned by `docker export` / `docker container export` when no -o/--output flag is given AND stdout is detected to be a terminal (export.go:50-53). Writing a raw tar archive to a terminal would dump binary garbage and corrupt terminal state, so the CLI refuses. The check uses dockerCLI.Out().IsTerminal().","triggerScenarios":"Running `docker export <container>` interactively in a shell without redirecting stdout or specifying -o. The combination of opts.output == \"\" and IsTerminal()==true triggers it.","commonSituations":"Forgetting the -o flag or a `> file.tar` redirect when testing export interactively; copy-pasting an export command that previously ran inside a pipe/script into a live terminal.","solutions":["Add the -o flag: `docker export -o out.tar <container>`.","Redirect stdout to a file: `docker export <container> > out.tar`.","Pipe into another consumer so stdout is not a terminal: `docker export <container> | tar -tv`."],"exampleFix":"// before\ndocker export mycontainer\n// after\ndocker export -o mycontainer.tar mycontainer","handlingStrategy":"validation","validationCode":"// In a wrapper, detect a terminal and force an output path.\nif out.IsTerminal() && opts.output == \"\" {\n    return errors.New(\"refusing binary output to terminal; pass -o or redirect\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass -o or redirect when scripting `docker export`.","Detect terminals in wrapper tools and fail fast with guidance.","Prefer `docker export -o file.tar` over stdout redirection for clarity."],"tags":["docker-cli","export","terminal","binary-output","safety-guard"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}