{"record":{"id":"68ea226946a8a497","repo":"docker/cli","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":"cli/command/container/export.go","lineNumber":58,"sourceCode":"\n\tflags := cmd.Flags()\n\n\tflags.StringVarP(&opts.output, \"output\", \"o\", \"\", \"Write to a file, instead of STDOUT\")\n\n\treturn cmd\n}\n\nfunc runExport(ctx context.Context, dockerCLI command.Cli, opts exportOptions) error {\n\tvar output io.Writer\n\tif opts.output == \"\" {\n\t\tif dockerCLI.Out().IsTerminal() {\n\t\t\treturn errors.New(\"cowardly refusing to save to a terminal. Use the -o flag or redirect\")\n\t\t}\n\t\toutput = dockerCLI.Out()\n\t} else {\n\t\twriter, err := atomicwriter.New(opts.output, 0o600)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to export container: %w\", err)\n\t\t}\n\t\tdefer writer.Close()\n\t\toutput = writer\n\t}\n\n\tresponseBody, err := dockerCLI.Client().ContainerExport(ctx, opts.container, client.ContainerExportOptions{})\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer responseBody.Close()\n\n\t_, err = io.Copy(output, responseBody)\n\treturn err\n}\n","sourceCodeStart":40,"sourceCodeEnd":73,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/container/export.go#L40-L73","documentation":"Returned by runExport in export.go:58 when atomicwriter.New fails to create the output file for `docker export -o <file>`. The wrapped %w is the os.OpenFile error from atomicwriter. This is a host-filesystem error, not a container-export error.","triggerScenarios":"`docker export -o /path/to/file <container>` where /path/to/file cannot be created: the parent directory does not exist, permission denied, read-only filesystem, or the path points to an existing directory.","commonSituations":"Typo in the output path, missing parent directory, no write permission on the target dir, or `-o` pointing at an existing directory.","solutions":["Ensure the parent directory exists and is writable: mkdir -p $(dirname OUTFILE) && chmod u+w $(dirname OUTFILE).","Remove or avoid pointing -o at an existing directory.","Check disk space and that the filesystem is mounted read-write.","Verify the path spelling."],"exampleFix":"# before\ndocker export -o /tmp/exports/box.tar box\n# /tmp/exports does not exist -> error\n\n# after\nmkdir -p /tmp/exports && docker export -o /tmp/exports/box.tar box","handlingStrategy":"validation","validationCode":"func validateExportOut(path string) error {\n    dir := filepath.Dir(path)\n    if info, err := os.Stat(dir); err != nil || !info.IsDir() {\n        return fmt.Errorf(\"output directory not usable: %s\", dir)\n    }\n    if f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0o600); err != nil {\n        return err\n    } else { f.Close(); os.Remove(path); }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := exportCmd.Run(); err != nil && strings.Contains(err.Error(), \"failed to export container\") {\n    // re-check path writability rather than treating as daemon error\n}","preventionTips":["Create the parent directory before running docker export -o.","Avoid pointing -o at an existing directory.","Ensure write permission and free disk space."],"tags":["container","export","filesystem","cli"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}