docker/cli ยท error

cowardly refusing to export to a terminal, specify a file pa

Error message

cowardly refusing to export to a terminal, specify a file path

What it means

`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.

Source

Thrown at cli/command/context/export.go:40

			var dest string
			if len(args) == 2 {
				dest = args[1]
			} else {
				dest = contextName + ".dockercontext"
			}
			return runExport(dockerCLI, contextName, dest)
		},
		ValidArgsFunction:     completeContextNames(dockerCLI, 1, true),
		DisableFlagsInUseLine: true,
	}
}

func writeTo(dockerCli command.Cli, reader io.Reader, dest string) error {
	var writer io.Writer
	var printDest bool
	if dest == "-" {
		if dockerCli.Out().IsTerminal() {
			return errors.New("cowardly refusing to export to a terminal, specify a file path")
		}
		writer = dockerCli.Out()
	} else {
		f, err := os.OpenFile(dest, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0o600)
		if err != nil {
			return err
		}
		defer f.Close()
		writer = f
		printDest = true
	}
	if _, err := io.Copy(writer, reader); err != nil {
		return err
	}
	if printDest {
		fmt.Fprintf(dockerCli.Err(), "Written file %q\n", dest)
	}
	return nil

View on GitHub (pinned to e9452d6e78)

Solutions

  1. Export to a file: `docker context export mycontext mycontext.dockercontext` (or omit the second arg for the default <name>.dockercontext).
  2. Keep `-` but redirect or pipe stdout: `docker context export mycontext - > ctx.tar` or `... - | ssh host 'docker context import ...'`.

Example fix

# before
docker context export mycontext -
# after
docker context export mycontext - > mycontext.tar
# or simply
docker context export mycontext

When it happens

Trigger: 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 `-`.

Common situations: 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.

Related errors


AI-assisted analysis of docker/cli@e9452d6e78 (2026-08-01). Data as JSON: /data/errors/c3384fa8e6f192aa.json. Report an issue: GitHub.