{"id":"b136053dbb392238","repo":"docker/cli","slug":"secret-file-is-required","errorCode":null,"errorMessage":"secret file is required","messagePattern":"secret file is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/secret/create.go","lineNumber":138,"sourceCode":"\n// readSecretData reads the secret from either stdin or the given fileName.\n//\n// It reads up to twice the maximum size of the secret ([maxSecretSize]),\n// just in case swarm's limit changes; this is only a safeguard to prevent\n// reading arbitrary files into memory.\nfunc readSecretData(in io.Reader, fileName string) ([]byte, error) {\n\tswitch fileName {\n\tcase \"-\":\n\t\tdata, err := io.ReadAll(io.LimitReader(in, 2*maxSecretSize))\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(\"secret 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*maxSecretSize))\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error reading from %s: %w\", fileName, err)\n\t\t}\n\t\tif len(data) == 0 {","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/docker/cli/blob/e9452d6e785f6e365712b9d71bd7517591773c86/cli/command/secret/create.go#L120-L156","documentation":"Raised by readSecretData when the file argument to `docker secret create` is an empty string. The CLI requires either a real file path or \"-\" for STDIN; an empty filename means it has no source for the secret data, so it errors immediately rather than creating an empty secret.","triggerScenarios":"Invoking `docker secret create NAME \"\"` (empty string as the file argument), or programmatic/script invocations where the file-path variable expands to an empty string, e.g. `docker secret create name \"$FILE\"` with FILE unset.","commonSituations":"Shell scripts with unquoted or unset path variables, wrappers or Makefiles that template the file argument, and automation that builds the argv list dynamically and inserts an empty element.","solutions":["Pass a real file path: `docker secret create mysecret ./secret.txt`.","Use `-` explicitly if the data comes from STDIN.","In scripts, validate the variable before use: `: \"${FILE:?secret file path required}\"`."],"exampleFix":"# before\ndocker secret create db_pass \"$SECRET_FILE\"   # SECRET_FILE empty\n# after\n: \"${SECRET_FILE:?path to secret file required}\"\ndocker secret create db_pass \"$SECRET_FILE\"","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":["docker-cli","swarm","secrets","cli-arguments","input-validation"],"analyzedSha":"e9452d6e785f6e365712b9d71bd7517591773c86","analyzedAt":"2026-08-01T07:09:22.474Z","schemaVersion":2}