docker/cli · error
error reading from STDIN: data is empty
Error message
error reading from STDIN: data is empty
What it means
Thrown by readSecretData when the data source is stdin ('-') and the read returns zero bytes. An empty secret is not permitted, so the create is refused (secret/create.go lines 133-135).
Solutions
- Ensure the piped stdin contains non-empty secret data.
- Use a file with actual content: 'docker secret create mysec ./secret.txt'.
- Verify the upstream producer of the data emits content before piping.
Example fix
# before printf '' | docker secret create mysec - # after printf '%s' "$SECRET_VALUE" | docker secret create mysec -
Defensive patterns
Strategy: validation
Validate before calling
// Validate non-empty stdin before creating the secret
data, err := io.ReadAll(io.LimitReader(in, 2*maxSecretSize))
if err != nil { return err }
if len(data) == 0 {
return fmt.Errorf("stdin secret data is empty")
} Prevention
- Check the upstream producer emits non-empty output before piping.
- Prefer a verified non-empty file over stdin for secrets.
- Log data length (not contents) to catch empty inputs in CI.
When it happens
Trigger: Running 'echo -n "" | docker secret create mysec -' or piping an empty stream/file as the secret content via '-'.
Common situations: Empty env var piped in; upstream command produced no output; redirecting from /dev/null.
Related errors
- when using secret driver secret data must be empty
- secret file is required
- node ID not found in /info
- invalid field ' ' must be a key=value pair
- every ip-range or gateway must have a corresponding subnet
AI-assisted analysis of docker/cli@4f84911bfe (2026-08-07).
Data as JSON: /api/errors/ab5e75635cc2035f.
Report an issue: GitHub.
Appendix: source
Thrown at cli/command/secret/create.go:134
// as defined by [MaxSecretSize] in SwarmKit.
//
// [MaxSecretSize]: https://pkg.go.dev/github.com/moby/swarmkit/v2@v2.0.0-20250103191802-8c1959736554/api/validation#MaxSecretSize
const maxSecretSize = 500 * 1024 // 500KB
// readSecretData reads the secret from either stdin or the given fileName.
//
// It reads up to twice the maximum size of the secret ([maxSecretSize]),
// just in case swarm's limit changes; this is only a safeguard to prevent
// reading arbitrary files into memory.
func readSecretData(in io.Reader, fileName string) ([]byte, error) {
switch fileName {
case "-":
data, err := io.ReadAll(io.LimitReader(in, 2*maxSecretSize))
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("secret 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*maxSecretSize))View on GitHub (pinned to 4f84911bfe)