{"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/5b2dbdbb8be64415eb6552f81ff7c449c8d251e6/build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/Docker.java#L145-L181","documentation":"Thrown by Docker.customizeHost as an IllegalArgumentException when both <docker><context> and <docker><host> are configured at the same time. These are two mutually exclusive ways to locate the Docker daemon: host is an explicit daemon URL, context is a named Docker CLI context to derive host/cert config from. Supplying both is ambiguous, so the plugin refuses to guess.","triggerScenarios":"Configuring <docker><host>unix:///var/run/docker.sock</host> and <docker><context>default</context> simultaneously in the build-image configuration; passing both -Dspring-boot.build-image.docker.host and -Dspring-boot.build-image.docker.context on the command line; inheriting a parent POM that sets one and overriding with the other in a child module.","commonSituations":"Migrating from host-based to context-based Docker config and forgetting to remove the old host entry; team-shared parent POM sets host while a developer's context-specific override adds context; CI injecting both via environment-derived properties.","solutions":["Decide on one strategy — keep either <host> or <context>, remove the other.","If targeting a remote daemon explicitly, use <host> and drop <context>.","If relying on Docker CLI contexts (e.g. colima, podman), use <context> and drop <host>.","Audit parent and child POMs for inherited docker configuration that combine the two."],"exampleFix":"// before\n<docker>\n  <host>unix:///var/run/docker.sock</host>\n  <context>default</context>\n</docker>\n// after — pick one\n<docker>\n  <host>unix:///var/run/docker.sock</host>\n</docker>","handlingStrategy":"validation","validationCode":"// Reject POMs that set both docker.host and docker.context\nboolean conflictingDockerCfg(String host, String context) {\n    return host != null && !host.isBlank() && context != null && !context.isBlank();\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Standardize on one Docker location strategy across the organization (host OR context).","In multi-module builds, audit parent POMs for inherited docker config that conflicts with child overrides.","Document the choice in the project README to prevent contributors from adding the other field."],"tags":["maven","spring-boot","build-image","docker","configuration"],"analyzedSha":"5b2dbdbb8be64415eb6552f81ff7c449c8d251e6","analyzedAt":"2026-08-04T18:53:14.967Z","schemaVersion":2}