{"record":{"id":"cb0411aa57491ab6","repo":"spring-projects/spring-boot","slug":"error-parsing-docker-configuration-file","errorCode":null,"errorMessage":"Error parsing Docker configuration file '{}'","messagePattern":"Error parsing Docker configuration file '(.+?)'","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"buildpack/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/configuration/DockerConfigurationMetadata.java","lineNumber":124,"sourceCode":"\t\tDockerConfig dockerConfig = createDockerConfig(configLocation);\n\t\tDockerContext dockerContext = createDockerContext(configLocation, dockerConfig.getCurrentContext());\n\t\treturn new DockerConfigurationMetadata(configLocation, dockerConfig, dockerContext);\n\t}\n\n\tprivate static String getUserHomeConfigLocation() {\n\t\treturn Path.of(System.getProperty(\"user.home\"), CONFIG_DIR).toString();\n\t}\n\n\tprivate static DockerConfig createDockerConfig(String configLocation) {\n\t\tPath path = Path.of(configLocation, CONFIG_FILE_NAME);\n\t\tif (!path.toFile().exists()) {\n\t\t\treturn DockerConfig.empty();\n\t\t}\n\t\ttry {\n\t\t\treturn DockerConfig.fromJson(readPathContent(path));\n\t\t}\n\t\tcatch (JacksonException ex) {\n\t\t\tthrow new IllegalStateException(\"Error parsing Docker configuration file '\" + path + \"'\", ex);\n\t\t}\n\t}\n\n\tprivate static DockerContext createDockerContext(String configLocation, @Nullable String currentContext) {\n\t\tif (currentContext == null || DEFAULT_CONTEXT.equals(currentContext)) {\n\t\t\treturn DockerContext.empty();\n\t\t}\n\t\tString hash = asHash(currentContext);\n\t\tPath metaPath = Path.of(configLocation, CONTEXTS_DIR, META_DIR, hash, CONTEXT_FILE_NAME);\n\t\tPath tlsPath = Path.of(configLocation, CONTEXTS_DIR, TLS_DIR, hash, DOCKER_ENDPOINT);\n\t\tif (!metaPath.toFile().exists()) {\n\t\t\tthrow new IllegalArgumentException(\"Docker context '\" + currentContext + \"' does not exist\");\n\t\t}\n\t\ttry {\n\t\t\tDockerContext context = DockerContext.fromJson(readPathContent(metaPath));\n\t\t\tif (tlsPath.toFile().isDirectory()) {\n\t\t\t\treturn context.withTlsPath(tlsPath.toString());\n\t\t\t}","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/spring-projects/spring-boot/blob/270dfe353fb830fd69b823a8a859287ff103854b/buildpack/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/configuration/DockerConfigurationMetadata.java#L106-L142","documentation":"Thrown by DockerConfigurationMetadata when reading ~/.docker/config.json (or $DOCKER_CONFIG/config.json). The file's existence is checked first, so this fires only when the file is present but its contents are not valid JSON. DockerConfig.fromJson calls SharedJsonMapper.get().readTree(json); the resulting JacksonException is wrapped in an IllegalStateException naming the offending path. The buildpack reads this file at the start of every Docker-driven build to discover registry auth, credential helpers, and the active Docker context.","triggerScenarios":"DockerConfigurationMetadata.from(environment) resolves a non-null config location, config.json exists, but DockerConfig.fromJson(readPathContent(path)) throws a JacksonException (stray comma, trailing data, BOM, truncated tail, hand-edited syntax error). Caught at line 123 and rethrown.","commonSituations":"Hand-editing ~/.docker/config.json and leaving a syntax error; a crashed docker login leaving a half-written file; a CI template (Jinja/mustache) leaving an unfilled placeholder; a UTF-8 BOM written by a Windows editor.","solutions":["Validate the file: run `jq ~/.docker/config.json` or `python -m json.tool ~/.docker/config.json` to find the syntax error.","Regenerate the file with `docker logout && docker login`.","If unrecoverable, back it up and delete it so DockerConfigurationMetadata falls back to DockerConfig.empty() (path.toFile().exists() == false at line 117)."],"exampleFix":"// before (broken JSON, trailing comma)\n{ \"auths\": { \"https://index.docker.io\": { \"auth\": \"...\" }}, }\n// after (valid JSON)\n{ \"auths\": { \"https://index.docker.io\": { \"auth\": \"...\" } } }","handlingStrategy":"validation","validationCode":"// Pre-validate config.json before invoking the build\nPath cfg = Path.of(\n    System.getenvOrDefault(\"DOCKER_CONFIG\",\n        Path.of(System.getProperty(\"user.home\"), \".docker\").toString()),\n    \"config.json\");\nif (Files.exists(cfg)) {\n    try {\n        SharedJsonMapper.get().readTree(Files.readString(cfg));\n    } catch (Exception e) {\n        throw new IllegalStateException(\n            \"~/.docker/config.json is invalid JSON: \" + e.getMessage(), e);\n    }\n}","typeGuard":null,"tryCatchPattern":"// Around the build invocation\ntry {\n    build.run();\n} catch (IllegalStateException ex) {\n    if (ex.getCause() instanceof JacksonException je\n            && ex.getMessage().startsWith(\"Error parsing Docker configuration file\")) {\n        // surface a user-facing hint pointing at the file in the message\n        throw new IllegalStateException(\n            \"Docker config.json is corrupt. Run `docker login` to regenerate it.\", ex);\n    }\n    throw ex;\n}","preventionTips":["Never hand-edit ~/.docker/config.json; use docker login / docker logout.","Add a `jq ~/.docker/config.json` step in CI before the buildpack build.","If templating config.json in CI, validate the rendered output with a JSON parser."],"tags":["docker","configuration","json","buildpack"],"backgroundTag":null,"analyzedSha":"270dfe353fb830fd69b823a8a859287ff103854b","analyzedAt":"2026-08-11T19:42:06.541Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}