{"record":{"id":"fa15014d010a0590","repo":"docker/cli","slug":"destination-can-not-be-empty","errorCode":null,"errorMessage":"destination can not be empty","messagePattern":"destination can not be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/container/cp.go","lineNumber":144,"sourceCode":"\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\n\tflags := cmd.Flags()\n\tflags.BoolVarP(&opts.followLink, \"follow-link\", \"L\", false, \"Always follow symlinks in SRC_PATH\")\n\tflags.BoolVarP(&opts.copyUIDGID, \"archive\", \"a\", false, \"Archive mode (copy all uid/gid information)\")","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/container/cp.go#L126-L162","documentation":"In newCopyCommand RunE at line 143-144, after confirming args[0] is non-empty, the code checks args[1] and returns errors.New(\"destination can not be empty\") if the second positional arg is the empty string. The copy must have a concrete destination (local path or container:path, or '-' to stream to stdout).","triggerScenarios":"Running `docker cp web:/tmp/file \"\"`, `docker cp ./file \"\"`, or any invocation where the destination positional argument is an empty string (unset/empty shell variable).","commonSituations":"Unset destination shell variables; programmatic argv construction leaving args[1] as \"\"; intending to stream to stdout but forgetting the '-' character.","solutions":["Provide a concrete destination path or container:path, or '-' to stream a tar to stdout.","Guard your shell variable: `${DEST:?destination required}`.","Double-check quoting/expansion when building args dynamically."],"exampleFix":"# before\nDEST=\"\"\ndocker cp web:/tmp/out \"$DEST\"\n# after\nDEST=./out.txt\ndocker cp web:/tmp/out \"$DEST\"\n# or stream to stdout\ndocker cp web:/tmp/out -","handlingStrategy":"validation","validationCode":"// Guard shell variable expansion:\n// ${DEST:?destination required} aborts if DEST is unset/empty.\n// In Go:\nif dest == \"\" { return errors.New(\"destination can not be empty\") }","typeGuard":null,"tryCatchPattern":"if err := cmd.Execute(); err != nil {\n    if strings.Contains(err.Error(), \"destination can not be empty\") {\n        // prompt for destination / fix argv\n    }\n}","preventionTips":["Quote and check shell variables before `docker cp` (`${DEST:?}`).","Use '-' explicitly to stream a tar to stdout.","Validate argv in wrappers before invoking docker."],"tags":["container","cp","validation","filesystem"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}