docker/cli · error
error reading content from
Error message
error reading content from %q: %v
What it means
Returned by runCreate() for `docker config create` when readConfigData() fails to read the data source (cli/command/config/create.go:71-74). readConfigData handles stdin ('-'), empty path, and a file path; this top-level wrapper reports the user-supplied file argument verbatim. The underlying cause is the inner error from readConfigData (file open failure, read failure, or empty-data error for the named file).
Solutions
- Verify the path exists and is readable: ls -l <file>.
- Ensure the file is non-empty (see errors 270) and is a regular file, not a directory.
- Expand shell variables/tildes before passing the argument, or use an absolute path.
- Use '-' to stream data via stdin if the source is a pipe.
Example fix
# before docker config create mycfg ~/missing.txt # ~ not expanded / file missing # after docker config create mycfg "$HOME/config.txt"
Defensive patterns
Strategy: validation
Validate before calling
// Pre-flight check for the config file argument.
func validateConfigSource(path string) error {
if path == "" { return errors.New("config file is required") }
if path == "-" { return nil }
fi, err := os.Stat(path)
if err != nil { return err }
if fi.IsDir() { return fmt.Errorf("%s is a directory", path) }
if fi.Size() == 0 { return fmt.Errorf("%s is empty", path) }
return nil
} Prevention
- Resolve the path to absolute and stat it before invoking docker config create.
- Use test -f and test -s in shell wrappers to guard against missing/empty files.
When it happens
Trigger: Running `docker config create NAME <file>` where the file cannot be opened, read, or is empty. The error is propagated from readConfigData and re-wrapped with the original %q file argument the user passed.
Common situations: Wrong path / typo, file does not exist, permission denied, file is a directory, or an empty file. Also when a tilde or shell variable did not expand (literal passed to the CLI).
Related errors
- error reading from : data is empty
- error reading from STDIN: data is empty
- config file is required
- cannot supply extra formatting options to the pretty…
- source is required
AI-assisted analysis of docker/cli@4f84911bfe (2026-08-07).
Data as JSON: /api/errors/4f3810529093bf8c.
Report an issue: GitHub.
Appendix: source
Thrown at cli/command/config/create.go:73
}
},
DisableFlagsInUseLine: true,
}
flags := cmd.Flags()
flags.VarP(&createOpts.labels, "label", "l", "Config labels")
flags.StringVar(&createOpts.templateDriver, "template-driver", "", "Template driver")
_ = flags.SetAnnotation("template-driver", "version", []string{"1.37"})
return cmd
}
// runCreate creates a config with the given options.
func runCreate(ctx context.Context, dockerCLI command.Cli, options createOptions) error {
apiClient := dockerCLI.Client()
configData, err := readConfigData(dockerCLI.In(), options.file)
if err != nil {
return fmt.Errorf("error reading content from %q: %v", options.file, err)
}
spec := swarm.ConfigSpec{
Annotations: swarm.Annotations{
Name: options.name,
Labels: opts.ConvertKVStringsToMap(options.labels.GetSlice()),
},
Data: configData,
}
if options.templateDriver != "" {
spec.Templating = &swarm.Driver{
Name: options.templateDriver,
}
}
r, err := apiClient.ConfigCreate(ctx, client.ConfigCreateOptions{
Spec: spec,
})
if err != nil {View on GitHub (pinned to 4f84911bfe)