caddyserver/caddy · error
reading config from stdin: %v
Error message
reading config from stdin: %v
What it means
The special config path '-' makes Caddy read the config from stdin, and this wraps an io.ReadAll(os.Stdin) failure. The pipe/stdin could not be read — broken pipe, closed stdin, or an OS-level read error.
Source
Thrown at cmd/main.go:166
// just so we don't have to check for nil
if logger == nil {
logger = zap.NewNop()
}
// specifying an adapter without a config file is ambiguous
if adapterName != "" && configFile == "" {
return nil, "", "", fmt.Errorf("cannot adapt config without config file (use --config)")
}
// load initial config and adapter
var config []byte
var cfgAdapter caddyconfig.Adapter
var err error
if configFile != "" {
if configFile == "-" {
config, err = io.ReadAll(os.Stdin)
if err != nil {
return nil, "", "", fmt.Errorf("reading config from stdin: %v", err)
}
logger.Info("using config from stdin")
} else {
config, err = os.ReadFile(configFile)
if err != nil {
return nil, "", "", fmt.Errorf("reading config from file: %v", err)
}
logger.Info("using config from file", zap.String("file", configFile))
}
} else if adapterName == "" {
// if the Caddyfile adapter is plugged in, we can try using an
// adjacent Caddyfile by default
cfgAdapter = caddyconfig.GetAdapter("caddyfile")
if cfgAdapter != nil {
config, err = os.ReadFile("Caddyfile")
if errors.Is(err, fs.ErrNotExist) {
// okay, no default Caddyfile; pretend like this never happened
cfgAdapter = nilView on GitHub (pinned to 50e54ee279)
Solutions
- Ensure something feeds stdin: cat config | caddy run --config -
- In service units, set StandardInput=file:/path or just use --config with a real path
- Verify the producer of the pipe succeeded before piping into caddy
Example fix
# before (systemd unit, stdin not wired) ExecStart=/usr/bin/caddy run --config - # after ExecStart=/usr/bin/caddy run --config /etc/caddy/Caddyfile --adapter caddyfile
Defensive patterns
Strategy: validation
Validate before calling
# Confirm stdin is wired before using '--config -': if [ -t 0 ]; then echo "refusing to read config from a terminal" >&2; exit 1; fi cat Caddyfile | caddy adapt --config - --adapter caddyfile
Prevention
- In systemd units, use StandardInput=file: or real file paths
- Guard scripts with [ -t 0 ] so a missing pipe fails fast
When it happens
Trigger: Running 'caddy run --config -' with stdin closed (no redirect in a cron/systemd unit), or an upstream producer of the pipe exiting mid-write.
Common situations: Systemd units without StandardInput=pipe; scripts where the generating command failed so the pipe delivered EOF/error; interactive shells where the command appears to hang then error.
Related errors
- reading confirmation bytes from stdin: %v
- invalid admin address %s: %v
- HTTP %d: reading error message: %v
- caddy responded with error: HTTP %d: %s
- no config file to load; either use --config flag or ensure C
AI-assisted analysis of caddyserver/caddy@50e54ee279 (2026-08-15).
Data as JSON: /api/errors/4af58f8b47729d42.
Report an issue: GitHub.