{"record":{"id":"a0cc4907b7d9b98f","repo":"docker/compose","slug":"failed-to-export-container-w","errorCode":null,"errorMessage":"failed to export container: %w","messagePattern":"failed to export container: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/compose/export.go","lineNumber":51,"sourceCode":"\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() {\n\t\tif err := responseBody.Close(); err != nil {\n\t\t\ts.events.On(errorEventf(name, \"Failed to close response body: %s\", err.Error()))\n\t\t}","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/docker/compose/blob/ddc4b044b62e9f715212ea4143fa830fac76382f/pkg/compose/export.go#L33-L69","documentation":"The --output value given to 'docker compose export' failed command.ValidateOutputPath — the path is not usable as a write target (unreadable parent dir, path is a directory, or otherwise invalid for creating/truncating a file) and compose fails before starting the export.","triggerScenarios":"docker compose export web -o /nonexistent-dir/x.tar, -o pointing at an existing directory, or an unwritable location; also weird paths like empty after shell expansion.","commonSituations":"Output dir not created yet; typo in path; read-only mount; using a path where a directory of the same name exists.","solutions":["mkdir -p the parent directory first","Point -o at a file path in a writable location","Ensure the path is a file, not an existing directory","Check filename validity (no stray shell characters)"],"exampleFix":"# before\ndocker compose export web -o /tmp/exports/fs.tar   # /tmp/exports missing\n# after\nmkdir -p /tmp/exports && docker compose export web -o /tmp/exports/fs.tar","handlingStrategy":"validation","validationCode":"if err := command.ValidateOutputPath(path); err != nil {\n    if mkErr := os.MkdirAll(filepath.Dir(path), 0o755); mkErr != nil { return mkErr }\n    if err := command.ValidateOutputPath(path); err != nil { return err }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["mkdir -p parent dirs in wrappers before export","Use absolute output paths in scripts","Ensure output path isn't an existing directory"],"tags":["export","filesystem","validation"],"backgroundTag":null,"analyzedSha":"ddc4b044b62e9f715212ea4143fa830fac76382f","analyzedAt":"2026-08-15T13:31:42.319Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}