{"record":{"id":"b17bc32a817e2660","repo":"docker/compose","slug":"output-option-is-required-when-exporting-to-termin","errorCode":null,"errorMessage":"output option is required when exporting to terminal","messagePattern":"output option is required when exporting to terminal","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/compose/export.go","lineNumber":48,"sourceCode":")\n\nfunc (s *composeService) Export(ctx context.Context, projectName string, options api.ExportOptions) error {\n\treturn Run(ctx, func(ctx context.Context) error {\n\t\treturn s.export(ctx, projectName, options)\n\t}, \"export\", s.events)\n}\n\nfunc (s *composeService) export(ctx context.Context, projectName string, options api.ExportOptions) error {\n\tprojectName = strings.ToLower(projectName)\n\n\tcontainer, err := s.getSpecifiedContainer(ctx, projectName, oneOffInclude, false, options.Service, options.Index)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif options.Output == \"\" {\n\t\tif s.stdout().IsTerminal() {\n\t\t\treturn fmt.Errorf(\"output option is required when exporting to terminal\")\n\t\t}\n\t} else if err := command.ValidateOutputPath(options.Output); err != nil {\n\t\treturn fmt.Errorf(\"failed to export container: %w\", err)\n\t}\n\n\tname := getCanonicalContainerName(container)\n\ts.events.On(api.Resource{\n\t\tID:     name,\n\t\tText:   api.StatusExporting,\n\t\tStatus: api.Working,\n\t})\n\n\tresponseBody, err := s.apiClient().ContainerExport(ctx, container.ID, client.ContainerExportOptions{})\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tdefer func() {","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/docker/compose/blob/ddc4b044b62e9f715212ea4143fa830fac76382f/pkg/compose/export.go#L30-L66","documentation":"'docker compose export' writes a container filesystem tarball; when no --output path is given and stdout is a TTY, dumping a binary tar stream to the terminal would corrupt it, so compose requires an explicit output. Non-terminal stdout (redirects/pipes) is allowed.","triggerScenarios":"Running 'docker compose export <service>' interactively in a shell without -o/--output while stdout is a TTY.","commonSituations":"Interactive use of the newer export command; forgetting that unlike some commands, export defaults to requiring a target here; scripting without redirect.","solutions":["Pass --output: docker compose export myservice -o fs.tar","Or redirect: docker compose export myservice > fs.tar","Verify the resulting tar: tar -tf fs.tar | head"],"exampleFix":"# before\ndocker compose export web\n# after\ndocker compose export web --output web-rootfs.tar","handlingStrategy":"validation","validationCode":"// API-level: require output before calling Export\nif opts.Output == \"\" && term.IsTerminal(os.Stdout.Fd()) {\n    return errors.New(\"--output is required in interactive terminals\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass --output for export in scripts and interactively","Redirect to a file when omitting -o"],"tags":["export","cli","stdout","validation"],"backgroundTag":null,"analyzedSha":"ddc4b044b62e9f715212ea4143fa830fac76382f","analyzedAt":"2026-08-15T13:31:42.319Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}