{"record":{"id":"3ca99d9509c2437b","repo":"spring-projects/spring-boot","slug":"invalid-docker-configuration-either-context-or-ho-3ca99d","errorCode":null,"errorMessage":"Invalid Docker configuration, either context or host can be provided but not both","messagePattern":"Invalid Docker configuration, either context or host can be provided but not both","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/Docker.java","lineNumber":163,"sourceCode":"\t * Returns this configuration as a {@link BuilderDockerConfiguration} instance. This\n\t * method should only be called when the configuration is complete and will no longer\n\t * be changed.\n\t * @param log the output log\n\t * @param publish whether the image should be published\n\t * @return the Docker configuration\n\t */\n\tBuilderDockerConfiguration asDockerConfiguration(Log log, boolean publish) {\n\t\tBuilderDockerConfiguration dockerConfiguration = new BuilderDockerConfiguration();\n\t\tdockerConfiguration = customizeHost(dockerConfiguration);\n\t\tdockerConfiguration = dockerConfiguration.withBindHostToBuilder(this.bindHostToBuilder);\n\t\tdockerConfiguration = customizeBuilderAuthentication(log, dockerConfiguration);\n\t\tdockerConfiguration = customizePublishAuthentication(log, dockerConfiguration, publish);\n\t\treturn dockerConfiguration;\n\t}\n\n\tprivate BuilderDockerConfiguration customizeHost(BuilderDockerConfiguration dockerConfiguration) {\n\t\tif (this.context != null && this.host != null) {\n\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\"Invalid Docker configuration, either context or host can be provided but not both\");\n\t\t}\n\t\tif (this.context != null) {\n\t\t\treturn dockerConfiguration.withContext(this.context);\n\t\t}\n\t\tif (this.host != null) {\n\t\t\treturn dockerConfiguration.withHost(this.host, this.tlsVerify, this.certPath);\n\t\t}\n\t\treturn dockerConfiguration;\n\t}\n\n\tprivate BuilderDockerConfiguration customizeBuilderAuthentication(Log log,\n\t\t\tBuilderDockerConfiguration dockerConfiguration) {\n\t\tDockerRegistryAuthentication authentication = DockerRegistryAuthentication.configuration(null,\n\t\t\t\t(message, ex) -> log.warn(message));\n\t\treturn dockerConfiguration.withBuilderRegistryAuthentication(\n\t\t\t\tgetRegistryAuthentication(\"builder\", this.builderRegistry, authentication));\n\t}","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/spring-projects/spring-boot/blob/270dfe353fb830fd69b823a8a859287ff103854b/build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/Docker.java#L145-L181","documentation":"IllegalArgumentException thrown by Docker.customizeHost when both <context> and <host> are configured simultaneously. The builder Docker connection can target either a named context or an explicit host, but not both — supplying both is contradictory, so the plugin refuses to guess.","triggerScenarios":"Setting both <docker><context>...</context> and <docker><host>...</host></host></docker> in the plugin configuration (or via the matching properties) when invoking build-image/push goals.","commonSituations":"Configuring <host> for a remote Docker daemon and <context> for a desktop Docker at the same time; copy-pasting examples that each set one; mixing docker.host and docker.context system properties with POM entries.","solutions":["Choose one: keep <context> for a Docker context name OR <host> for an explicit daemon URL, and remove the other.","Check that system properties -Ddocker.host / -Ddocker.context aren't both set in MAVEN_OPTS or CI.","If using docker.context, ensure the context exists (`docker context ls`)."],"exampleFix":"// before: <docker><host>tcp://docker.local:2376</host><context>default</context></docker>\n// after:  <docker><host>tcp://docker.local:2376</host></docker>","handlingStrategy":"validation","validationCode":"// Configuration validation before invoking build-image:\nif (docker.getContext() != null && docker.getHost() != null) {\n    throw new IllegalArgumentException(\n        \"Configure either docker.context OR docker.host, not both.\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    // invoke build-image\n} catch (IllegalArgumentException ex) {\n    if (ex.getMessage().contains(\"either context or host\")) {\n        // drop one of <context>/<host> and retry\n    }\n    throw ex;\n}","preventionTips":["Standardize on either context-based or host-based Docker config per environment.","Check MAVEN_OPTS / system properties for stray -Ddocker.host and -Ddocker.context.","Document the chosen mode in the project README."],"tags":["spring-boot","maven-plugin","docker","build-image","configuration"],"backgroundTag":null,"analyzedSha":"270dfe353fb830fd69b823a8a859287ff103854b","analyzedAt":"2026-08-11T19:42:06.541Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}