{"id":"5dfb12356a7092d8","repo":"docker/cli","slug":"got-a-device","errorCode":null,"errorMessage":"got a device","messagePattern":"got a device","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/utils.go","lineNumber":92,"sourceCode":"\t\t}\n\n\t\tif fileInfo.Mode().IsDir() || fileInfo.Mode().IsRegular() {\n\t\t\treturn nil\n\t\t}\n\n\t\tif err := ValidateOutputPathFileMode(fileInfo.Mode()); err != nil {\n\t\t\treturn fmt.Errorf(\"invalid output path: %q must be a directory or a regular file: %w\", path, err)\n\t\t}\n\t}\n\treturn nil\n}\n\n// ValidateOutputPathFileMode validates the output paths of the \"docker cp\" command\n// and serves as a helper to [ValidateOutputPath]\nfunc ValidateOutputPathFileMode(fileMode os.FileMode) error {\n\tswitch {\n\tcase fileMode&os.ModeDevice != 0:\n\t\treturn errors.New(\"got a device\")\n\tcase fileMode&os.ModeIrregular != 0:\n\t\treturn errors.New(\"got an irregular file\")\n\t}\n\treturn nil\n}\n\nfunc invalidParameter(err error) error {\n\treturn invalidParameterErr{err}\n}\n\ntype invalidParameterErr struct{ error }\n\nfunc (invalidParameterErr) InvalidParameter() {}\n\nfunc notFound(err error) error {\n\treturn notFoundErr{err}\n}\n","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/docker/cli/blob/e9452d6e785f6e365712b9d71bd7517591773c86/cli/command/utils.go#L74-L110","documentation":"Returned by ValidateOutputPathFileMode, used by `docker cp` output-path validation, when the destination file mode has os.ModeDevice set. Copying onto a device node (block or character device like /dev/sda or /dev/null) is refused because docker cp only supports directories and regular files as destinations; the message is wrapped into \"invalid output path: %q must be a directory or a regular file\".","triggerScenarios":"`docker cp container:/path /dev/<something>` or any cp invocation whose local destination resolves to an existing device file; ValidateOutputPath stats the path and its mode has ModeDevice set at cli/command/utils.go:92.","commonSituations":"Attempting `docker cp ctr:/file /dev/stdout`-style tricks with real device nodes; scripts that computed a wrong destination path landing in /dev; destination path collisions with device files in containers/chroots.","solutions":["Copy to a regular file or directory instead: `docker cp ctr:/file ./file`.","If you want the content on stdout, use `docker cp ctr:/file -` (streams a tar) or `docker exec ctr cat /file > out`.","Check and fix the destination path your script computes so it doesn't point into /dev."],"exampleFix":"# before\ndocker cp mycontainer:/etc/hosts /dev/sda\n# after\ndocker cp mycontainer:/etc/hosts ./hosts","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":["docker-cli","docker-cp","filesystem","validation"],"analyzedSha":"e9452d6e785f6e365712b9d71bd7517591773c86","analyzedAt":"2026-08-01T07:09:22.474Z","schemaVersion":2}