docker/cli · error

config file is required

Error message

config file is required

What it means

Raised by readConfigData in cli/command/config/create.go when the file argument for `docker config create` is an empty string. The command needs either a real file path or "-" for stdin; an empty name means there is no source for the config data at all, so it fails before touching the filesystem.

Source

Thrown at cli/command/config/create.go:122

// readConfigData reads the config from either stdin or the given fileName.
//
// It reads up to twice the maximum size of the config ([maxConfigSize]),
// just in case swarm's limit changes; this is only a safeguard to prevent
// reading arbitrary files into memory.
func readConfigData(in io.Reader, fileName string) ([]byte, error) {
	switch fileName {
	case "-":
		data, err := io.ReadAll(io.LimitReader(in, 2*maxConfigSize))
		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("config 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*maxConfigSize))
		if err != nil {
			return nil, fmt.Errorf("error reading from %s: %w", fileName, err)
		}
		if len(data) == 0 {

View on GitHub (pinned to e9452d6e78)

Solutions

  1. Make sure the file argument expands to a real path — quote and validate it: `: "${CONFIG_FILE:?must be set}"` before the docker call.
  2. Use `-` explicitly if you intend to read from stdin: `docker config create myconfig -`.
  3. For programmatic callers, populate options.File (path or "-") before calling RunConfigCreate.

Example fix

# before
docker config create app-config "$CONFIG_FILE"   # CONFIG_FILE unset -> ""
# after
: "${CONFIG_FILE:?CONFIG_FILE must point to the config file}"
docker config create app-config "$CONFIG_FILE"

When it happens

Trigger: Invoking the config-create code path with fileName == "" — on the CLI this means the file argument was supplied as an empty string (e.g. an unset shell variable: `docker config create myconfig "$CONFIG_FILE"`), or a programmatic caller of RunConfigCreate passed empty options.File.

Common situations: Shell scripts where the config-file variable is undefined or emptied by a failed earlier step; templated CI jobs where the parameter wasn't substituted; Go code driving the config create logic with a zero-value options struct.

Related errors


AI-assisted analysis of docker/cli@e9452d6e78 (2026-08-01). Data as JSON: /data/errors/71d83c08acebe1a7.json. Report an issue: GitHub.