hashicorp/nomad · error

Failed to parse auth config file: %v

Error message

Failed to parse auth config file: %v

What it means

After successfully opening the auth config file, loadDockerConfig parses it with configfile.LoadFromReader. If the contents are not valid Docker config JSON, the error is wrapped as 'Failed to parse auth config file'. The file exists but its content is unusable for auth lookups.

Source

Thrown at drivers/docker/utils.go:75

func dockerImageRef(repo string, tag string) string {
	if tag == "" {
		return repo
	}
	return fmt.Sprintf("%s:%s", repo, tag)
}

// loadDockerConfig loads the docker config at the specified path, returning an
// error if it couldn't be read.
func loadDockerConfig(file string) (*configfile.ConfigFile, error) {
	f, err := os.Open(file)
	if err != nil {
		return nil, fmt.Errorf("Failed to open auth config file: %v, error: %v", file, err)
	}
	defer f.Close()

	cfile := new(configfile.ConfigFile)
	if err = cfile.LoadFromReader(f); err != nil {
		return nil, fmt.Errorf("Failed to parse auth config file: %v", err)
	}
	return cfile, nil
}

// repositoryInfo contains the subset of repository metadata needed for auth
// lookup against Docker config files and credential helpers.
type repositoryInfo struct {
	Index *registrytypes.IndexInfo
}

// parseRepositoryInfo takes a repo and returns the repository metadata needed
// for interacting with a Docker config object.
func parseRepositoryInfo(repo string) (*repositoryInfo, error) {
	name, err := reference.ParseNormalizedNamed(repo)
	if err != nil {
		return nil, fmt.Errorf("Failed to parse named repo %q: %v", repo, err)
	}

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Validate the file content against Docker's config.json schema (try: docker login then diff, or jq . file)
  2. Fix JSON syntax errors (trailing commas, quotes) or regenerate via docker login
  3. Replace YAML-style or partial credential content with a complete {"auths":{...}} document
  4. Rewrite the file atomically (write temp file then rename) to avoid truncated reads

Example fix

// before
{ "auths": { "registry.example.com": {"auth": "...",} } }
// after
{ "auths": { "registry.example.com": {"auth": "..."} } }
Defensive patterns

Strategy: validation

Validate before calling

raw, err := os.ReadFile(dockerAuthPath)
if err != nil { return err }
var probe map[string]json.RawMessage
if err := json.Unmarshal(raw, &probe); err != nil {
    return fmt.Errorf("docker auth config is not valid JSON: %w", err)
}
if _, ok := probe["auths"]; !ok {
    return errors.New("docker auth config missing 'auths' key")
}

Prevention

When it happens

Trigger: cfile.LoadFromReader(f) fails: file contains invalid JSON, is empty when auth is expected, was truncated by a failed write, or contains YAML/credentials format instead of Docker's config.json schema.

Common situations: Manually edited config.json with syntax errors; pasting a raw 'auths' value instead of the full config document; half-written file from an interrupted docker login; templating engine rendering invalid output.

Understand the failure class

Related errors


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/4da9028e96586901. Report an issue: GitHub.