spring-projects/spring-boot · error · IllegalArgumentException
Docker context '{}' does not exist
Error message
Docker context '{}' does not exist What it means
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.
Source
Thrown at buildpack/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/configuration/DockerConfigurationMetadata.java:136
return DockerConfig.empty();
}
try {
return DockerConfig.fromJson(readPathContent(path));
}
catch (JacksonException ex) {
throw new IllegalStateException("Error parsing Docker configuration file '" + path + "'", ex);
}
}
private static DockerContext createDockerContext(String configLocation, @Nullable String currentContext) {
if (currentContext == null || DEFAULT_CONTEXT.equals(currentContext)) {
return DockerContext.empty();
}
String hash = asHash(currentContext);
Path metaPath = Path.of(configLocation, CONTEXTS_DIR, META_DIR, hash, CONTEXT_FILE_NAME);
Path tlsPath = Path.of(configLocation, CONTEXTS_DIR, TLS_DIR, hash, DOCKER_ENDPOINT);
if (!metaPath.toFile().exists()) {
throw new IllegalArgumentException("Docker context '" + currentContext + "' does not exist");
}
try {
DockerContext context = DockerContext.fromJson(readPathContent(metaPath));
if (tlsPath.toFile().isDirectory()) {
return context.withTlsPath(tlsPath.toString());
}
return context;
}
catch (JacksonException ex) {
throw new IllegalStateException("Error parsing Docker context metadata file '" + metaPath + "'", ex);
}
}
private static String asHash(String currentContext) {
try {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] hash = digest.digest(currentContext.getBytes(StandardCharsets.UTF_8));
return HexFormat.of().formatHex(hash);View on GitHub (pinned to 270dfe353f)
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.
Example fix
// before: config.json points at a removed context
{ "currentContext": "staging" }
// (no contexts/meta/<sha256(staging)>/meta.json present)
// after: run `docker context use default` ->
{ "currentContext": "default" } Defensive patterns
Strategy: validation
Validate before calling
// Verify the active context's metadata directory exists
String ctx = readCurrentContextFromConfigJson(); // null or "default" -> safe
if (ctx != null && !"default".equals(ctx)) {
String hash = HexFormat.of().formatHex(
MessageDigest.getInstance("SHA-256").digest(ctx.getBytes(UTF_8)));
Path meta = Path.of(configLocation, "contexts", "meta", hash, "meta.json");
if (!Files.exists(meta)) {
throw new IllegalStateException(
"Active Docker context '" + ctx + "' is dangling. Run `docker context ls` and `docker context use <valid>`.");
}
} Try / catch
try {
metadata.forContext(name);
} catch (IllegalArgumentException ex) {
if (ex.getMessage().startsWith("Docker context '")) {
// prompt: list available contexts, offer to switch to default
}
throw ex;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: `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.
Related errors
- Error parsing Docker context metadata file '{}'
- Error parsing Docker configuration file '{}'
- Error reading Docker configuration file '{}'
- Invalid Docker configuration, either context or host can be
- Invalid Docker {} registry configuration, either token or us
AI-assisted analysis of spring-projects/spring-boot@270dfe353f (2026-08-11).
Data as JSON: /api/errors/c1476503c7141c22.
Report an issue: GitHub.