{"record":{"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":"exception","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/270dfe353fb830fd69b823a8a859287ff103854b/build-plugin/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/DockerSpec.java#L118-L154","documentation":"Thrown by DockerSpec.customizeHost when both 'context' and 'host' are set on the Docker configuration. These are mutually exclusive ways to locate the Docker daemon: 'context' references a named Docker context, 'host' specifies a direct host URL. The plugin detects both being non-null and rejects the configuration before attempting to connect.","triggerScenarios":"Configuring bootBuildImage (or related Docker-using tasks) with both docker.context and docker.host set simultaneously in the DSL, e.g. docker { context = 'my-context'; host = 'tcp://docker:2375' }.","commonSituations":"Switching from a direct host connection to a Docker context (or vice versa) and forgetting to unset the old property. Copying example DSL that sets both. CI configs that set DOCKER_HOST as well as a context.","solutions":["Choose one: set either docker.context OR docker.host, not both.","If you switched to using a Docker context, remove the docker.host line.","If you switched to a direct host, remove the docker.context line.","Verify no environment variable (DOCKER_HOST) is implicitly setting host while you also set context in DSL."],"exampleFix":"// before\ntasks.bootBuildImage {\n    docker {\n        context = \"remote\"\n        host = \"tcp://docker.example.com:2375\"  // throws: both set\n    }\n}\n// after\ntasks.bootBuildImage {\n    docker {\n        host = \"tcp://docker.example.com:2375\"\n    }\n}","handlingStrategy":"validation","validationCode":"// Validate mutual exclusivity before the task runs.\nString ctx = dockerSpec.getContext().getOrNull();\nString host = dockerSpec.getHost().getOrNull();\nif (ctx != null && host != null) {\n    throw new GradleException(\"Set either context OR host, not both.\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set either docker.context or docker.host, never both.","When switching connection methods, unset the old property.","Check for DOCKER_HOST environment variable that may implicitly set host alongside a DSL context."],"tags":["gradle","validation","build-image","docker","configuration","mutually-exclusive"],"backgroundTag":null,"analyzedSha":"270dfe353fb830fd69b823a8a859287ff103854b","analyzedAt":"2026-08-11T19:42:06.541Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}