docker/cli · error

error reading from STDIN: data is empty

Error message

error reading from STDIN: data is empty

What it means

readConfigData (cli/command/config/create.go:110) handles the '-' (stdin) case for `docker config create NAME -`. It reads up to 2*maxConfigSize bytes from stdin; if the resulting data has length 0 it returns errors.New("error reading from STDIN: data is empty") at line 118. An empty Swarm config is invalid, so the input must contain at least one byte.

Solutions

  1. Ensure the piped/redirected stdin source actually contains data: `cat nonemptyfile | docker config create mycfg -`.
  2. Check the preceding pipeline step did not fail or emit empty output (`set -o pipefail`, inspect `$?`).
  3. If you have a file, pass it directly instead of '-': `docker config create mycfg ./config.txt`.
  4. Verify the file/source is not /dev/null or an empty file.

Example fix

# before
echo -n '' | docker config create mycfg -
# after
printf 'my config contents' | docker config create mycfg -
Defensive patterns

Strategy: validation

Validate before calling

// If streaming via stdin, check readability/non-emptiness upstream:
fi, _ := os.Stdin.Stat()
if (fi.Mode()&os.ModeCharDevice) != 0 || fi.Size() == 0 {
    return errors.New("stdin is empty; provide config data or a file path")
}

Try / catch

data, err := readConfigData(in, file)
if err != nil {
    if errors.Is(err, errEmptyStdin) /* if exposed */ || strings.Contains(err.Error(), "data is empty") {
        // guide user to provide non-empty stdin
    }
    return err
}

Prevention

When it happens

Trigger: Running `docker config create mycfg -` with stdin closed, redirected from /dev/null, or piped from a command that produced no output (e.g. `echo -n '' | docker config create mycfg -`, or `< /dev/null`, or a here-doc with no content).

Common situations: Piping `cat` of an empty file; a preceding command in a pipeline that failed silently and emitted nothing; CI with stdin not attached.

Related errors


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

Appendix: source

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

// as defined by [MaxConfigSize] in SwarmKit.
//
// [MaxConfigSize]: https://pkg.go.dev/github.com/moby/swarmkit/v2@v2.0.0-20250103191802-8c1959736554/manager/controlapi#MaxConfigSize
const maxConfigSize = 1000 * 1024 // 1000KB

// readConfigData reads the config from either stdin or the given fileName.
//
// It reads up to twice the maximum size of the config ([maxConfigSize]),
// just in case swarm's limit changes; this is only a safeguard to prevent
// reading arbitrary files into memory.
func readConfigData(in io.Reader, fileName string) ([]byte, error) {
	switch fileName {
	case "-":
		data, err := io.ReadAll(io.LimitReader(in, 2*maxConfigSize))
		if err != nil {
			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))

View on GitHub (pinned to 4f84911bfe)