docker/compose · error

destination "%s:%s" must be a directory or a regular file: %

Error message

destination "%s:%s" must be a directory or a regular file: %w

What it means

Error "destination "%s:%s" must be a directory or a regular file: %w" thrown in docker/compose.

Source

Thrown at pkg/compose/cp.go:185

		linkTarget := dstStat.LinkTarget
		if !isAbs(linkTarget) {
			// Join with the parent directory.
			dstParent, _ := archive.SplitPathDirEntry(dstPath)
			linkTarget = filepath.Join(dstParent, linkTarget)
		}

		dstInfo.Path = linkTarget
		res, err = s.apiClient().ContainerStatPath(ctx, containerID, client.ContainerStatPathOptions{
			Path: linkTarget,
		})
		if err == nil {
			dstStat = res.Stat
		}
	}

	// Validate the destination path
	if err := command.ValidateOutputPathFileMode(dstStat.Mode); err != nil {
		return fmt.Errorf(`destination "%s:%s" must be a directory or a regular file: %w`, containerID, dstPath, err)
	}

	// Ignore any error and assume that the parent directory of the destination
	// path exists, in which case the copy may still succeed. If there is any
	// type of conflict (e.g., non-directory overwriting an existing directory
	// or vice versa) the extraction will fail. If the destination simply did
	// not exist, but the parent directory does, the extraction will still
	// succeed.
	if err == nil {
		dstInfo.Exists, dstInfo.IsDir = true, dstStat.Mode.IsDir()
	}

	var (
		content         io.Reader
		resolvedDstPath string
	)

	if srcPath == "-" {

View on GitHub (pinned to ddc4b044b6)

Solutions

  1. Choose a destination path inside the container that is an existing directory or a regular file path.
  2. Create the destination directory in the container first (docker compose exec <service> mkdir -p <path>), then retry the copy.

When it happens

Trigger: During 'docker compose cp' into a container, the destination path inside the container is neither a directory nor a regular file, so the copy target is invalid.

Common situations: The destination is a symlink to something unusual, a special device, or a non-existent path when copying multiple sources which require a directory target.


AI-assisted analysis of docker/compose@ddc4b044b6 (2026-08-15). Data as JSON: /api/errors/9d433151dd0490c0. Report an issue: GitHub.