docker/cli · error
source can not be empty
Error message
source can not be empty
What it means
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).
Source
Thrown at cli/command/container/cp.go:141
// newCopyCommand creates a new `docker cp` command
func newCopyCommand(dockerCLI command.Cli) *cobra.Command {
var opts copyOptions
cmd := &cobra.Command{
Use: `cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-
docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH`,
Short: "Copy files/folders between a container and the local filesystem",
Long: `Copy files/folders between a container and the local filesystem
Use '-' as the source to read a tar archive from stdin
and extract it to a directory destination in a container.
Use '-' as the destination to stream a tar archive of a
container source to stdout.`,
Args: cli.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
if args[0] == "" {
return errors.New("source can not be empty")
}
if args[1] == "" {
return errors.New("destination can not be empty")
}
opts.source = args[0]
opts.destination = args[1]
if !cmd.Flag("quiet").Changed {
// User did not specify "quiet" flag; suppress output if no terminal is attached
opts.quiet = !dockerCLI.Out().IsTerminal()
}
return runCopy(cmd.Context(), dockerCLI, opts)
},
Annotations: map[string]string{
"aliases": "docker container cp, docker cp",
},
DisableFlagsInUseLine: true,
}
View on GitHub (pinned to e9452d6e78)
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.
Example fix
# before
docker cp "$SRC" mycontainer:/app/ # SRC unset -> empty source
# after
: "${SRC:?SRC must be set to the file to copy}"
docker cp "$SRC" mycontainer:/app/ When it happens
Trigger: `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/`.
Common situations: 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.
Related errors
- config file is required
- plugin candidate path cannot be empty
- plugin SchemaVersion version cannot be empty
- no name set for network
- invalid storage option
AI-assisted analysis of docker/cli@e9452d6e78 (2026-08-01).
Data as JSON: /data/errors/644e8944f0133c3c.json.
Report an issue: GitHub.