docker/cli · error

error reading from

Error message

error reading from %s: %w

What it means

Returned by readConfigData() when opening the config file fails (cli/command/config/create.go:131-134). It uses sequential.Open (FILE_FLAG_SEQUENTIAL_SCAN on Windows) and wraps the os.Open error with the file path. Typical causes map to os.PathError: ENOENT (not found), EACCES (permission denied), or EISDIR (path is a directory).

Solutions

  1. Confirm the file exists and is a regular file: test -f <file>.
  2. Fix permissions so the current user can read it: chmod u+r <file>.
  3. Use an absolute path or ensure the correct working directory.
  4. If the source is a directory, tar/encode it first or pick the actual file.

Example fix

# before
docker config create mycfg ./config   # ./config is a directory
# after
docker config create mycfg ./config/app.conf
Defensive patterns

Strategy: validation

Validate before calling

func validateConfigFile(path string) error {
    fi, err := os.Stat(path)
    if err != nil { return fmt.Errorf("cannot open %s: %w", path, err) }
    if fi.IsDir() { return fmt.Errorf("%s is a directory", path) }
    return nil
}

Prevention

When it happens

Trigger: Running `docker config create NAME <file>` where sequential.Open(fileName) returns an error: file does not exist, no read permission, or the path resolves to a directory.

Common situations: Typo in path, relative path evaluated from an unexpected working directory, permission denied, or pointing at a directory instead of a file.

Related errors


AI-assisted analysis of docker/cli@4f84911bfe (2026-08-07). Data as JSON: /api/errors/a1484988d9c32fe4. Report an issue: GitHub.

Appendix: source

Thrown at cli/command/config/create.go:133

			return nil, fmt.Errorf("error reading from STDIN: %w", err)
		}
		if len(data) == 0 {
			return nil, errors.New("error reading from STDIN: data is empty")
		}
		return data, nil
	case "":
		return nil, errors.New("config file is required")
	default:
		// Open file with [FILE_FLAG_SEQUENTIAL_SCAN] on Windows, which
		// prevents Windows from aggressively caching it. We expect this
		// file to be only read once. Given that this is expected to be
		// a small file, this may not be a significant optimization, so
		// we could choose to omit this, and use a regular [os.Open].
		//
		// [FILE_FLAG_SEQUENTIAL_SCAN]: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea#FILE_FLAG_SEQUENTIAL_SCAN
		f, err := sequential.Open(fileName)
		if err != nil {
			return nil, fmt.Errorf("error reading from %s: %w", fileName, err)
		}
		defer f.Close()
		data, err := io.ReadAll(io.LimitReader(f, 2*maxConfigSize))
		if err != nil {
			return nil, fmt.Errorf("error reading from %s: %w", fileName, err)
		}
		if len(data) == 0 {
			return nil, fmt.Errorf("error reading from %s: data is empty", fileName)
		}
		return data, nil
	}
}

View on GitHub (pinned to 4f84911bfe)