{"record":{"id":"c1476503c7141c22","repo":"spring-projects/spring-boot","slug":"docker-context-does-not-exist","errorCode":null,"errorMessage":"Docker context '{}' does not exist","messagePattern":"Docker context '(.+?)' does not exist","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"buildpack/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/configuration/DockerConfigurationMetadata.java","lineNumber":136,"sourceCode":"\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}\n\t\t\treturn context;\n\t\t}\n\t\tcatch (JacksonException ex) {\n\t\t\tthrow new IllegalStateException(\"Error parsing Docker context metadata file '\" + metaPath + \"'\", ex);\n\t\t}\n\t}\n\n\tprivate static String asHash(String currentContext) {\n\t\ttry {\n\t\t\tMessageDigest digest = MessageDigest.getInstance(\"SHA-256\");\n\t\t\tbyte[] hash = digest.digest(currentContext.getBytes(StandardCharsets.UTF_8));\n\t\t\treturn HexFormat.of().formatHex(hash);","sourceCodeStart":118,"sourceCodeEnd":154,"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#L118-L154","documentation":"config.json declares a currentContext that is neither null nor \"default\". DockerConfigurationMetadata.createDockerContext SHA-256-hashes the context name, builds the path contexts/meta/<hash>/meta.json under the config dir, and throws IllegalArgumentException when that file does not exist. Docker stores each named context in a directory named by the hex SHA-256 of the context name, so a missing directory means Docker itself has no record of that context.","triggerScenarios":"createDockerConfig returned a non-null currentContext; createDockerContext runs, asHash(name) computes the SHA-256, Path.of(configLocation, CONTEXTS_DIR, META_DIR, hash, CONTEXT_FILE_NAME) is built, and metaPath.toFile().exists() returns false at line 135.","commonSituations":"`docker context rm <name>` left currentContext pointing at the removed context; DOCKER_CONFIG switched to a directory that lacks the contexts/ tree; only config.json was copied between machines without its contexts/ directory; casing/whitespace mismatch between the stored name and what docker context create used.","solutions":["Run `docker context ls` to see which contexts actually exist in this config dir.","Repair the dangling reference: `docker context use default` (or another existing context) to rewrite currentContext.","Recreate the context with `docker context create <name> ...` if it should exist."],"exampleFix":"// before: config.json points at a removed context\n{ \"currentContext\": \"staging\" }\n// (no contexts/meta/<sha256(staging)>/meta.json present)\n// after: run `docker context use default` ->\n{ \"currentContext\": \"default\" }","handlingStrategy":"validation","validationCode":"// Verify the active context's metadata directory exists\nString ctx = readCurrentContextFromConfigJson(); // null or \"default\" -> safe\nif (ctx != null && !\"default\".equals(ctx)) {\n    String hash = HexFormat.of().formatHex(\n        MessageDigest.getInstance(\"SHA-256\").digest(ctx.getBytes(UTF_8)));\n    Path meta = Path.of(configLocation, \"contexts\", \"meta\", hash, \"meta.json\");\n    if (!Files.exists(meta)) {\n        throw new IllegalStateException(\n            \"Active Docker context '\" + ctx + \"' is dangling. Run `docker context ls` and `docker context use <valid>`.\");\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    metadata.forContext(name);\n} catch (IllegalArgumentException ex) {\n    if (ex.getMessage().startsWith(\"Docker context '\")) {\n        // prompt: list available contexts, offer to switch to default\n    }\n    throw ex;\n}","preventionTips":["After `docker context rm <name>`, run `docker context use default` to clear currentContext.","When copying a docker config between machines, copy the whole directory including contexts/.","In CI, prefer not setting currentContext unless the contexts/ tree is also present."],"tags":["docker","configuration","docker-context","buildpack"],"backgroundTag":null,"analyzedSha":"270dfe353fb830fd69b823a8a859287ff103854b","analyzedAt":"2026-08-11T19:42:06.541Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}