{"id":"1d70827a5ac5492b","repo":"docker/cli","slug":"must-specify-at-least-one-container-source","errorCode":null,"errorMessage":"must specify at least one container source","messagePattern":"must specify at least one container source","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/container/cp.go","lineNumber":245,"sourceCode":"\tvar direction copyDirection\n\tif srcContainer != \"\" {\n\t\tdirection |= fromContainer\n\t\tcopyConfig.container = srcContainer\n\t}\n\tif destContainer != \"\" {\n\t\tdirection |= toContainer\n\t\tcopyConfig.container = destContainer\n\t}\n\n\tswitch direction {\n\tcase fromContainer:\n\t\treturn copyFromContainer(ctx, dockerCli, copyConfig)\n\tcase toContainer:\n\t\treturn copyToContainer(ctx, dockerCli, copyConfig)\n\tcase acrossContainers:\n\t\treturn errors.New(\"copying between containers is not supported\")\n\tdefault:\n\t\treturn errors.New(\"must specify at least one container source\")\n\t}\n}\n\nfunc resolveLocalPath(localPath string) (absPath string, _ error) {\n\tabsPath, err := filepath.Abs(localPath)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\treturn archive.PreserveTrailingDotOrSeparator(absPath, localPath), nil\n}\n\nfunc copyFromContainer(ctx context.Context, dockerCLI command.Cli, copyConfig cpConfig) (err error) {\n\tdstPath := copyConfig.destPath\n\tsrcPath := copyConfig.sourcePath\n\n\tif dstPath != \"-\" {\n\t\t// Get an absolute destination path.\n\t\tdstPath, err = resolveLocalPath(dstPath)","sourceCodeStart":227,"sourceCodeEnd":263,"githubUrl":"https://github.com/docker/cli/blob/e9452d6e785f6e365712b9d71bd7517591773c86/cli/command/container/cp.go#L227-L263","documentation":"The default branch of the direction switch in runCopy: neither the source nor the destination argument was recognized as a CONTAINER:PATH reference, so there is no container endpoint at all. docker cp only copies between a container and the local filesystem, so at least one side must name a container.","triggerScenarios":"`docker cp ./a ./b` where both arguments are plain local paths (no `container:` prefix on either side), leaving both fromContainer and toContainer direction bits unset.","commonSituations":"Forgetting the `container:` prefix on the container-side path; scripts where the container name variable is empty so the argument degrades to a bare path (e.g. `docker cp \"$CTR:/logs\" .` with $CTR unset yields `:/logs` edge cases); confusing docker cp with plain cp.","solutions":["Prefix the container-side argument with the container name or ID, e.g. `docker cp mycontainer:/var/log/app.log ./`.","Verify shell variables holding the container name are non-empty before invoking the command.","Use plain `cp` if both paths are genuinely on the host."],"exampleFix":"# before\ndocker cp /var/log/app.log ./app.log\n# after\ndocker cp mycontainer:/var/log/app.log ./app.log","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}