{"id":"2f587686fa1e1227","repo":"spring-projects/spring-boot","slug":"invalid-docker-configuration-either-context-or-ho","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":"GradleException","httpStatus":null,"severity":"error","filePath":"build-plugin/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/DockerSpec.java","lineNumber":136,"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 * @return the Docker configuration\n\t */\n\tBuilderDockerConfiguration asDockerConfiguration() {\n\t\tBuilderDockerConfiguration dockerConfiguration = new BuilderDockerConfiguration();\n\t\tdockerConfiguration = customizeHost(dockerConfiguration);\n\t\tdockerConfiguration = dockerConfiguration.withBindHostToBuilder(getBindHostToBuilder().get());\n\t\tdockerConfiguration = customizeBuilderAuthentication(dockerConfiguration);\n\t\tdockerConfiguration = customizePublishAuthentication(dockerConfiguration);\n\t\treturn dockerConfiguration;\n\t}\n\n\tprivate BuilderDockerConfiguration customizeHost(BuilderDockerConfiguration dockerConfiguration) {\n\t\tString context = getContext().getOrNull();\n\t\tString host = getHost().getOrNull();\n\t\tif (context != null && host != null) {\n\t\t\tthrow new GradleException(\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 (context != null) {\n\t\t\treturn dockerConfiguration.withContext(context);\n\t\t}\n\t\tif (host != null) {\n\t\t\treturn dockerConfiguration.withHost(host, getTlsVerify().get(), getCertPath().getOrNull());\n\t\t}\n\t\treturn dockerConfiguration;\n\t}\n\n\tprivate BuilderDockerConfiguration customizeBuilderAuthentication(BuilderDockerConfiguration dockerConfiguration) {\n\t\treturn dockerConfiguration.withBuilderRegistryAuthentication(getRegistryAuthentication(\"builder\",\n\t\t\t\tthis.builderRegistry, DockerRegistryAuthentication.configuration(null)));\n\t}\n\n\tprivate BuilderDockerConfiguration customizePublishAuthentication(BuilderDockerConfiguration dockerConfiguration) {\n\t\treturn dockerConfiguration","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/spring-projects/spring-boot/blob/5b2dbdbb8be64415eb6552f81ff7c449c8d251e6/build-plugin/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/DockerSpec.java#L118-L154","documentation":"Thrown by DockerSpec.customizeHost() during asDockerConfiguration() when both docker.context and docker.host are set. Docker can be targeted either by a context name or by an explicit host URL, but not both; setting both is ambiguous and rejected as GradleException at line 136.","triggerScenarios":"bootBuildImage runs createRequest() -> asDockerConfiguration() -> customizeHost(); getContext().getOrNull() and getHost().getOrNull() are both non-null, triggering the throw.","commonSituations":"CI sets docker.host while the developer's build also sets docker.context; copy-pasting both from docs; switching from context-based to host-based config without removing the other; environment overlay (gradle.properties) supplying one and the build script the other.","solutions":["Choose one: set either docker { context = 'my-context' } or docker { host = 'tcp://docker:2375' }, not both.","Remove conflicting entries from gradle.properties, environment, and the build script.","If using Docker contexts exclusively, leave host unset (and vice versa).","Run ./gradlew properties | grep -i docker to see effective values."],"exampleFix":"// before: both set\nbootBuildImage {\n    docker {\n        context = 'desktop-linux'\n        host = 'tcp://docker.example.com:2375'\n    }\n}\n// after: pick one\nbootBuildImage {\n    docker {\n        host = 'tcp://docker.example.com:2375'\n        tlsVerify = true\n    }\n}\n","handlingStrategy":"validation","validationCode":"// Validate that context and host are not both set before running bootBuildImage\nval ctx = (tasks.named(\"bootBuildImage\").get() as org.springframework.boot.gradle.tasks.bundling.BootBuildImage)\n    .docker.context.orNull\nval host = (tasks.named(\"bootBuildImage\").get() as org.springframework.boot.gradle.tasks.bundling.BootBuildImage)\n    .docker.host.orNull\ncheck(ctx == null || host == null) {\n    \"Set either docker.context or docker.host, not both\"\n}\n","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Standardize on one Docker targeting mechanism (context OR host) across the team.","Provide docker settings through a single source (build script or gradle.properties), not both.","Document the chosen mechanism in CI configuration."],"tags":["gradle","boot-build-image","docker","configuration","validation"],"analyzedSha":"5b2dbdbb8be64415eb6552f81ff7c449c8d251e6","analyzedAt":"2026-08-04T18:53:14.967Z","schemaVersion":2}