docker/cli · error

error reading from : data is empty

Error message

error reading from %s: data is empty

What it means

Returned by readConfigData() when the named config file is opened and read successfully but contains zero bytes (cli/command/config/create.go:140-142). A Swarm config must carry data, so an empty payload is rejected. This mirrors the stdin empty-data check at line 118 but is specific to the file path branch.

Solutions

  1. Confirm the file has content: test -s <file> (succeeds only if non-empty).
  2. Regenerate the file from its source if an upstream step failed.
  3. Provide the intended content or use stdin with real data.

Example fix

# before
docker config create mycfg /tmp/empty.txt   # 0 bytes
# after
printf 'key=value' > /tmp/config.txt
docker config create mycfg /tmp/config.txt
Defensive patterns

Strategy: validation

Validate before calling

func validateConfigNonEmpty(path string) error {
    fi, err := os.Stat(path)
    if err != nil { return err }
    if fi.Size() == 0 { return fmt.Errorf("%s is empty", path) }
    return nil
}

Prevention

When it happens

Trigger: Running `docker config create NAME <file>` where <file> exists, is readable, but is 0 bytes long. The read succeeds (yielding len(data)==0) and triggers this explicit guard.

Common situations: Truncated/empty file from a failed upstream process, creating a config from a placeholder/template that was never filled, or pointing at /dev/null by mistake.

Related errors


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

Appendix: source

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

	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)