docker/cli ยท error

must specify at least one container source

Error message

must specify at least one container source

What it means

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.

Source

Thrown at cli/command/container/cp.go:245

	var direction copyDirection
	if srcContainer != "" {
		direction |= fromContainer
		copyConfig.container = srcContainer
	}
	if destContainer != "" {
		direction |= toContainer
		copyConfig.container = destContainer
	}

	switch direction {
	case fromContainer:
		return copyFromContainer(ctx, dockerCli, copyConfig)
	case toContainer:
		return copyToContainer(ctx, dockerCli, copyConfig)
	case acrossContainers:
		return errors.New("copying between containers is not supported")
	default:
		return errors.New("must specify at least one container source")
	}
}

func resolveLocalPath(localPath string) (absPath string, _ error) {
	absPath, err := filepath.Abs(localPath)
	if err != nil {
		return "", err
	}
	return archive.PreserveTrailingDotOrSeparator(absPath, localPath), nil
}

func copyFromContainer(ctx context.Context, dockerCLI command.Cli, copyConfig cpConfig) (err error) {
	dstPath := copyConfig.destPath
	srcPath := copyConfig.sourcePath

	if dstPath != "-" {
		// Get an absolute destination path.
		dstPath, err = resolveLocalPath(dstPath)

View on GitHub (pinned to e9452d6e78)

Solutions

  1. Prefix the container-side argument with the container name or ID, e.g. `docker cp mycontainer:/var/log/app.log ./`.
  2. Verify shell variables holding the container name are non-empty before invoking the command.
  3. Use plain `cp` if both paths are genuinely on the host.

Example fix

# before
docker cp /var/log/app.log ./app.log
# after
docker cp mycontainer:/var/log/app.log ./app.log

When it happens

Trigger: `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.

Common situations: 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.

Related errors


AI-assisted analysis of docker/cli@e9452d6e78 (2026-08-01). Data as JSON: /data/errors/1d70827a5ac5492b.json. Report an issue: GitHub.