{"record":{"id":"cc8dd768c6b6ca31","repo":"docker/cli","slug":"loading-config-file-w","errorCode":null,"errorMessage":"loading config file: %w","messagePattern":"loading config file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/config/config.go","lineNumber":145,"sourceCode":"\tif configDir == \"\" {\n\t\tconfigDir = Dir()\n\t}\n\treturn load(configDir)\n}\n\nfunc load(configDir string) (*configfile.ConfigFile, error) {\n\tfilename := filepath.Join(configDir, ConfigFileName)\n\tconfigFile := configfile.New(filename)\n\n\tfile, err := os.Open(filename)\n\tif err != nil {\n\t\tif os.IsNotExist(err) {\n\t\t\t// It is OK for no configuration file to be present, in which\n\t\t\t// case we return a default struct.\n\t\t\treturn configFile, nil\n\t\t}\n\t\t// Any other error happening when failing to read the file must be returned.\n\t\treturn configFile, fmt.Errorf(\"loading config file: %w\", err)\n\t}\n\tdefer func() { _ = file.Close() }()\n\terr = configFile.LoadFromReader(file)\n\tif err != nil {\n\t\terr = fmt.Errorf(\"parsing config file (%s): %w\", filename, err)\n\t}\n\treturn configFile, err\n}\n\n// LoadDefaultConfigFile attempts to load the default config file and returns\n// a reference to the ConfigFile struct. If none is found or when failing to load\n// the configuration file, it initializes a default ConfigFile struct. If no\n// credentials-store is set in the configuration file, it attempts to discover\n// the default store to use for the current platform.\n//\n// Important: LoadDefaultConfigFile prints a warning to stderr when failing to\n// load the configuration file, but otherwise ignores errors. Consumers should\n// consider using [Load] (and [credentials.DetectDefaultStore]) to detect errors","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/config/config.go#L127-L163","documentation":"Returned by the internal `load` function (config.go:137-145) when os.Open of the config file (config.json) fails with any error OTHER than \"not exists\". The not-exists case is tolerated (default struct returned), but permission errors, I/O errors, or broken symlinks are wrapped with this message.","triggerScenarios":"config.Load(configDir) -> load() -> os.Open(filename) returns a non-IsNotExist error. Typical causes: the file exists but lacks read permission, the parent directory is unreadable, or a symlink target is broken in a way that yields EIO/EACCES rather than ENOENT.","commonSituations":"The `~/.docker/config.json` file (or DOCKER_CONFIG location) exists but is owned by another user / has mode 000, was created on a different user account, or sits on a filesystem that fails to open. Also occurs when DOCKER_CONFIG points to a directory the process cannot traverse.","solutions":["Check permissions on the file reported: `ls -la ~/.docker/config.json` and the parent directory; ensure the current user can read both.","Verify DOCKER_CONFIG points to a readable, existing directory (`echo $DOCKER_CONFIG`).","If the file is corrupt or locked by another process, fix the lock or restore a valid config.","As a last resort, move the unreadable file aside and let Docker recreate a default config."],"exampleFix":"# before — file not readable\n$ ls -la ~/.docker/config.json\n-rw------- 1 root root ... config.json\n# after — fix ownership/permissions\n$ sudo chown $USER:$USER ~/.docker/config.json\n$ chmod 600 ~/.docker/config.json","handlingStrategy":"validation","validationCode":"// Pre-check readability before relying on config.Load.\nif _, err := os.Stat(filename); err != nil {\n    return fmt.Errorf(\"config file inaccessible: %w\", err)\n}\n// ensure readable bit for current user\nif fi, _ := os.Stat(filename); fi != nil && fi.Mode().Perm()&0o400 == 0 {\n    return errors.New(\"config file not readable\")\n}","typeGuard":null,"tryCatchPattern":"cfg, err := config.Load(dir)\nif err != nil {\n    return fmt.Errorf(\"cannot load docker config from %s: %w\", dir, err)\n}","preventionTips":["Ensure `~/.docker/config.json` and its parent dir are owned and readable by the running user.","Set DOCKER_CONFIG to a directory the process can traverse and read.","Check permissions as part of container image setup scripts."],"tags":["config","filesystem","permissions","config-json"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}