{"id":"c3384fa8e6f192aa","repo":"docker/cli","slug":"cowardly-refusing-to-export-to-a-terminal-specify","errorCode":null,"errorMessage":"cowardly refusing to export to a terminal, specify a file path","messagePattern":"cowardly refusing to export to a terminal, specify a file path","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/context/export.go","lineNumber":40,"sourceCode":"\t\t\tvar dest string\n\t\t\tif len(args) == 2 {\n\t\t\t\tdest = args[1]\n\t\t\t} else {\n\t\t\t\tdest = contextName + \".dockercontext\"\n\t\t\t}\n\t\t\treturn runExport(dockerCLI, contextName, dest)\n\t\t},\n\t\tValidArgsFunction:     completeContextNames(dockerCLI, 1, true),\n\t\tDisableFlagsInUseLine: true,\n\t}\n}\n\nfunc writeTo(dockerCli command.Cli, reader io.Reader, dest string) error {\n\tvar writer io.Writer\n\tvar printDest bool\n\tif dest == \"-\" {\n\t\tif dockerCli.Out().IsTerminal() {\n\t\t\treturn errors.New(\"cowardly refusing to export to a terminal, specify a file path\")\n\t\t}\n\t\twriter = dockerCli.Out()\n\t} else {\n\t\tf, err := os.OpenFile(dest, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0o600)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tdefer f.Close()\n\t\twriter = f\n\t\tprintDest = true\n\t}\n\tif _, err := io.Copy(writer, reader); err != nil {\n\t\treturn err\n\t}\n\tif printDest {\n\t\tfmt.Fprintf(dockerCli.Err(), \"Written file %q\\n\", dest)\n\t}\n\treturn nil","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/docker/cli/blob/e9452d6e785f6e365712b9d71bd7517591773c86/cli/command/context/export.go#L22-L58","documentation":"`docker context export <name> -` streams a binary tar archive of the context to stdout. writeTo refuses when stdout is an interactive terminal (dockerCli.Out().IsTerminal()), because dumping raw tar bytes to a TTY would garble the terminal and is never what the user wants. The 'cowardly refusing' phrasing follows the tar/gzip tradition for the same guard.","triggerScenarios":"Running `docker context export mycontext -` directly in an interactive shell with stdout not redirected. Does not trigger when stdout is piped (`| gzip`), redirected (`> file`), or when a file argument is given instead of `-`.","commonSituations":"Copy-pasting a pipeline example but omitting the redirection; testing the command interactively before wiring it into a script; expecting `-` to mean 'default file name' rather than stdout.","solutions":["Export to a file: `docker context export mycontext mycontext.dockercontext` (or omit the second arg for the default <name>.dockercontext).","Keep `-` but redirect or pipe stdout: `docker context export mycontext - > ctx.tar` or `... - | ssh host 'docker context import ...'`."],"exampleFix":"# before\ndocker context export mycontext -\n# after\ndocker context export mycontext - > mycontext.tar\n# or simply\ndocker context export mycontext","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":["docker-cli","context","stdout","terminal"],"analyzedSha":"e9452d6e785f6e365712b9d71bd7517591773c86","analyzedAt":"2026-08-01T07:09:22.474Z","schemaVersion":2}