docker/cli ยท error
cowardly refusing to save to a terminal. Use the -o flag or
Error message
cowardly refusing to save to a terminal. Use the -o flag or redirect
What it means
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.
Source
Thrown at cli/command/container/export.go:52
Annotations: map[string]string{
"aliases": "docker container export, docker export",
},
ValidArgsFunction: completion.ContainerNames(dockerCLI, true),
DisableFlagsInUseLine: true,
}
flags := cmd.Flags()
flags.StringVarP(&opts.output, "output", "o", "", "Write to a file, instead of STDOUT")
return cmd
}
func runExport(ctx context.Context, dockerCLI command.Cli, opts exportOptions) error {
var output io.Writer
if opts.output == "" {
if dockerCLI.Out().IsTerminal() {
return errors.New("cowardly refusing to save to a terminal. Use the -o flag or redirect")
}
output = dockerCLI.Out()
} else {
writer, err := atomicwriter.New(opts.output, 0o600)
if err != nil {
return fmt.Errorf("failed to export container: %w", err)
}
defer writer.Close()
output = writer
}
responseBody, err := dockerCLI.Client().ContainerExport(ctx, opts.container, client.ContainerExportOptions{})
if err != nil {
return err
}
defer responseBody.Close()
_, err = io.Copy(output, responseBody)View on GitHub (pinned to e9452d6e78)
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`.
Example fix
# before docker export mycontainer # after docker export -o mycontainer.tar mycontainer
When it happens
Trigger: `docker export mycontainer` run in an interactive shell with stdout attached to a TTY and without `-o` and without piping/redirecting the output.
Common situations: 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.
Related errors
- cowardly refusing to export to a terminal, specify a file pa
- cowardly refusing to save to a terminal. Use the -o flag or
- failed to parse hook template
- unexpected hook response type:
- plugin candidate path cannot be empty
AI-assisted analysis of docker/cli@e9452d6e78 (2026-08-01).
Data as JSON: /data/errors/72fd0e6678261c20.json.
Report an issue: GitHub.