{"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":"error","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/e9452d6e785f6e365712b9d71bd7517591773c86/cli/command/container/export.go#L34-L70","documentation":"runExport refuses to write the raw tar archive produced by `docker export` to stdout when stdout is an interactive terminal and no -o/--output file was given. Dumping binary tar data to a TTY would garble the terminal, so the CLI 'cowardly refuses' (a nod to GNU tar's phrasing) unless output is redirected or a file is specified.","triggerScenarios":"`docker export mycontainer` run in an interactive shell with stdout attached to a TTY and without `-o` and without piping/redirecting the output.","commonSituations":"First-time use of docker export interactively to 'see' the result; forgetting the redirect in an interactive session that works fine in scripts (where stdout is not a TTY); same pattern exists for docker save.","solutions":["Write to a file with the flag: `docker export -o container.tar mycontainer`.","Redirect stdout: `docker export mycontainer > container.tar`.","Pipe it onward: `docker export mycontainer | gzip > container.tar.gz`."],"exampleFix":"# before\ndocker export mycontainer\n# after\ndocker export -o mycontainer.tar mycontainer","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":["docker-cli","docker-export","terminal","stdout"],"analyzedSha":"e9452d6e785f6e365712b9d71bd7517591773c86","analyzedAt":"2026-08-01T07:09:22.474Z","schemaVersion":2}