{"id":"644e8944f0133c3c","repo":"docker/cli","slug":"source-can-not-be-empty","errorCode":null,"errorMessage":"source can not be empty","messagePattern":"source can not be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/container/cp.go","lineNumber":141,"sourceCode":"\n// newCopyCommand creates a new `docker cp` command\nfunc newCopyCommand(dockerCLI command.Cli) *cobra.Command {\n\tvar opts copyOptions\n\n\tcmd := &cobra.Command{\n\t\tUse: `cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-\n\tdocker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH`,\n\t\tShort: \"Copy files/folders between a container and the local filesystem\",\n\t\tLong: `Copy files/folders between a container and the local filesystem\n\nUse '-' as the source to read a tar archive from stdin\nand extract it to a directory destination in a container.\nUse '-' as the destination to stream a tar archive of a\ncontainer source to stdout.`,\n\t\tArgs: cli.ExactArgs(2),\n\t\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\t\tif args[0] == \"\" {\n\t\t\t\treturn errors.New(\"source can not be empty\")\n\t\t\t}\n\t\t\tif args[1] == \"\" {\n\t\t\t\treturn errors.New(\"destination can not be empty\")\n\t\t\t}\n\t\t\topts.source = args[0]\n\t\t\topts.destination = args[1]\n\t\t\tif !cmd.Flag(\"quiet\").Changed {\n\t\t\t\t// User did not specify \"quiet\" flag; suppress output if no terminal is attached\n\t\t\t\topts.quiet = !dockerCLI.Out().IsTerminal()\n\t\t\t}\n\t\t\treturn runCopy(cmd.Context(), dockerCLI, opts)\n\t\t},\n\t\tAnnotations: map[string]string{\n\t\t\t\"aliases\": \"docker container cp, docker cp\",\n\t\t},\n\t\tDisableFlagsInUseLine: true,\n\t}\n","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/docker/cli/blob/e9452d6e785f6e365712b9d71bd7517591773c86/cli/command/container/cp.go#L123-L159","documentation":"Raised in the RunE of `docker cp` (cli/command/container/cp.go): the command takes exactly two positional arguments, and if the first (the source) is an empty string it is rejected before any path parsing. An empty source can't be resolved to either a local path or a CONTAINER:PATH reference, so the CLI fails fast with this message (the destination has a matching 'destination can not be empty' check).","triggerScenarios":"`docker cp \"\" <dest>` — an explicitly empty first argument, which passes the ExactArgs(2) count check but is a zero-length string. Almost always produced by an unset or empty shell variable, e.g. `docker cp \"$SRC\" mycontainer:/app/`.","commonSituations":"CI/deploy scripts where the source-path variable wasn't exported or a prior step that computes it failed; quoting bugs where \"$1\" in a wrapper script is empty; templated commands (Ansible/Make) rendering an empty value into the source slot.","solutions":["Ensure the source argument is non-empty before calling docker cp — in shell, guard with `: \"${SRC:?source path must be set}\"`.","Check the failing script's variable assignment and the exit status of whatever computes the path.","Remember the valid forms: `docker cp LOCAL_PATH CONTAINER:DEST` or `docker cp CONTAINER:SRC LOCAL_PATH`, with `-` allowed for tar streams via stdin/stdout."],"exampleFix":"# before\ndocker cp \"$SRC\" mycontainer:/app/   # SRC unset -> empty source\n# after\n: \"${SRC:?SRC must be set to the file to copy}\"\ndocker cp \"$SRC\" mycontainer:/app/","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":["docker-cli","cp","shell-scripting","validation"],"analyzedSha":"e9452d6e785f6e365712b9d71bd7517591773c86","analyzedAt":"2026-08-01T07:09:22.474Z","schemaVersion":2}