docker/cli · error
destination can not be empty
Error message
destination can not be empty
What it means
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.
Source
Thrown at cli/command/container/cp.go:144
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,
}
flags := cmd.Flags()
flags.BoolVarP(&opts.followLink, "follow-link", "L", false, "Always follow symlinks in SRC_PATH")
flags.BoolVarP(&opts.copyUIDGID, "archive", "a", false, "Archive mode (copy all uid/gid information)")View on GitHub (pinned to e9452d6e78)
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.
Example fix
# before docker cp file.txt "$DEST" # $DEST is empty # after DEST="mycontainer:/tmp/" docker cp file.txt "$DEST"
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- must specify at least one container source
- copying between containers is not supported
- content size not available for stdin
- you cannot start and attach multiple containers at once
- got a device
AI-assisted analysis of docker/cli@e9452d6e78 (2026-08-01).
Data as JSON: /data/errors/fa15014d010a0590.json.
Report an issue: GitHub.