{"id":"ae64a524d4684d3b","repo":"docker/cli","slug":"error-reading-from-stdin-data-is-empty","errorCode":null,"errorMessage":"error reading from STDIN: data is empty","messagePattern":"error reading from STDIN: data is empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/config/create.go","lineNumber":118,"sourceCode":"// as defined by [MaxConfigSize] in SwarmKit.\n//\n// [MaxConfigSize]: https://pkg.go.dev/github.com/moby/swarmkit/v2@v2.0.0-20250103191802-8c1959736554/manager/controlapi#MaxConfigSize\nconst maxConfigSize = 1000 * 1024 // 1000KB\n\n// readConfigData reads the config from either stdin or the given fileName.\n//\n// It reads up to twice the maximum size of the config ([maxConfigSize]),\n// just in case swarm's limit changes; this is only a safeguard to prevent\n// reading arbitrary files into memory.\nfunc readConfigData(in io.Reader, fileName string) ([]byte, error) {\n\tswitch fileName {\n\tcase \"-\":\n\t\tdata, err := io.ReadAll(io.LimitReader(in, 2*maxConfigSize))\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error reading from STDIN: %w\", err)\n\t\t}\n\t\tif len(data) == 0 {\n\t\t\treturn nil, errors.New(\"error reading from STDIN: data is empty\")\n\t\t}\n\t\treturn data, nil\n\tcase \"\":\n\t\treturn nil, errors.New(\"config file is required\")\n\tdefault:\n\t\t// Open file with [FILE_FLAG_SEQUENTIAL_SCAN] on Windows, which\n\t\t// prevents Windows from aggressively caching it. We expect this\n\t\t// file to be only read once. Given that this is expected to be\n\t\t// a small file, this may not be a significant optimization, so\n\t\t// we could choose to omit this, and use a regular [os.Open].\n\t\t//\n\t\t// [FILE_FLAG_SEQUENTIAL_SCAN]: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea#FILE_FLAG_SEQUENTIAL_SCAN\n\t\tf, err := sequential.Open(fileName)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error reading from %s: %w\", fileName, err)\n\t\t}\n\t\tdefer f.Close()\n\t\tdata, err := io.ReadAll(io.LimitReader(f, 2*maxConfigSize))","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/docker/cli/blob/e9452d6e785f6e365712b9d71bd7517591773c86/cli/command/config/create.go#L100-L136","documentation":"Raised by readConfigData in cli/command/config/create.go when `docker config create` is told to read the config payload from stdin (file argument \"-\") but stdin yields zero bytes. Swarm configs must carry content, so an empty payload is rejected before any API call is made.","triggerScenarios":"Running `docker config create <name> -` with nothing piped to stdin, piping a command that produces no output (e.g. an empty file via `cat empty | docker config create name -`), or a redirect from a zero-byte file.","commonSituations":"CI scripts where the upstream command generating the config (envsubst, jq, vault read) failed silently or printed to stderr instead of stdout; heredocs with wrong delimiters; running the command interactively and immediately hitting Ctrl-D; a pipeline stage whose file path variable expanded to an empty file.","solutions":["Verify the data you are piping is non-empty before invoking docker: `test -s config.txt` or inspect the generator's output first.","Fix the producing command in the pipeline (check its exit code and stdout — output going to stderr is not piped).","If the content lives in a file, pass the filename directly instead of piping: `docker config create myconfig ./config.txt`."],"exampleFix":"# before (generator wrote to stderr, stdin empty)\nsome-generator 2>&1 >/dev/null | docker config create app-config -\n# after\nsome-generator > config.txt\ntest -s config.txt\ndocker config create app-config ./config.txt","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":["docker-cli","swarm-config","stdin","pipeline"],"analyzedSha":"e9452d6e785f6e365712b9d71bd7517591773c86","analyzedAt":"2026-08-01T07:09:22.474Z","schemaVersion":2}