docker/cli ยท error

got a device

Error message

got a device

What it means

Returned by ValidateOutputPathFileMode, used by `docker cp` output-path validation, when the destination file mode has os.ModeDevice set. Copying onto a device node (block or character device like /dev/sda or /dev/null) is refused because docker cp only supports directories and regular files as destinations; the message is wrapped into "invalid output path: %q must be a directory or a regular file".

Source

Thrown at cli/command/utils.go:92

		}

		if fileInfo.Mode().IsDir() || fileInfo.Mode().IsRegular() {
			return nil
		}

		if err := ValidateOutputPathFileMode(fileInfo.Mode()); err != nil {
			return fmt.Errorf("invalid output path: %q must be a directory or a regular file: %w", path, err)
		}
	}
	return nil
}

// ValidateOutputPathFileMode validates the output paths of the "docker cp" command
// and serves as a helper to [ValidateOutputPath]
func ValidateOutputPathFileMode(fileMode os.FileMode) error {
	switch {
	case fileMode&os.ModeDevice != 0:
		return errors.New("got a device")
	case fileMode&os.ModeIrregular != 0:
		return errors.New("got an irregular file")
	}
	return nil
}

func invalidParameter(err error) error {
	return invalidParameterErr{err}
}

type invalidParameterErr struct{ error }

func (invalidParameterErr) InvalidParameter() {}

func notFound(err error) error {
	return notFoundErr{err}
}

View on GitHub (pinned to e9452d6e78)

Solutions

  1. Copy to a regular file or directory instead: `docker cp ctr:/file ./file`.
  2. If you want the content on stdout, use `docker cp ctr:/file -` (streams a tar) or `docker exec ctr cat /file > out`.
  3. Check and fix the destination path your script computes so it doesn't point into /dev.

Example fix

# before
docker cp mycontainer:/etc/hosts /dev/sda
# after
docker cp mycontainer:/etc/hosts ./hosts

When it happens

Trigger: `docker cp container:/path /dev/<something>` or any cp invocation whose local destination resolves to an existing device file; ValidateOutputPath stats the path and its mode has ModeDevice set at cli/command/utils.go:92.

Common situations: Attempting `docker cp ctr:/file /dev/stdout`-style tricks with real device nodes; scripts that computed a wrong destination path landing in /dev; destination path collisions with device files in containers/chroots.

Related errors


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