{"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/e9452d6e785f6e365712b9d71bd7517591773c86/cli/command/container/cp.go#L126-L162","documentation":"Raised by the `docker cp` command's argument validation in the cobra RunE handler when the second positional argument (the destination) is an empty string. The command requires exactly two args (SRC and DEST), and an empty destination cannot be resolved to either a local path or a CONTAINER:PATH spec, so the CLI fails fast before contacting the daemon.","triggerScenarios":"Running `docker cp SRC \"\"` where the destination argument is an empty string — typically via shell variable expansion like `docker cp file.txt \"$DEST\"` when $DEST is unset, or scripted invocations passing an empty argv element.","commonSituations":"Shell scripts or CI pipelines building the destination from an environment variable that is unset or empty; quoting mistakes that produce an empty argument; programmatic wrappers around the Docker CLI passing empty strings.","solutions":["Check that the destination variable is set before invoking docker cp (e.g. `: \"${DEST:?must be set}\"` in bash).","Pass an explicit destination such as `container:/path` or a local path.","Use `-` as the destination if you intend to stream a tar archive to stdout."],"exampleFix":"# before\ndocker cp file.txt \"$DEST\"   # $DEST is empty\n# after\nDEST=\"mycontainer:/tmp/\"\ndocker cp file.txt \"$DEST\"","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":["docker-cli","docker-cp","argument-validation"],"analyzedSha":"e9452d6e785f6e365712b9d71bd7517591773c86","analyzedAt":"2026-08-01T07:09:22.474Z","schemaVersion":2}