You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在使用spring-boot:build-image构建镜像时指定--network=host参数

Configure Network Mode for Spring Boot's spring-boot:build-image Build Phase

Hey there, I totally get what you're trying to do—switching from direct docker build to Spring Boot's build-image plugin but needing that --network host setting for the build stage. Here's how you can make it work:

Option 1: Pass via Command Line

You can directly add the network configuration as a system property when running the Maven command. The property you need is spring-boot.build-image.builder.network:

mvn spring-boot:build-image -Dspring-boot.build-image.imageName=foo/bar -Dspring-boot.build-image.builder.network=host

This tells the underlying Cloud Native Buildpacks builder to use the host network during the build process, just like your old docker build --network host command did.

Option 2: Configure in pom.xml (Permanent Setup)

If you don't want to type the property every time, you can hardcode it in your Maven project's pom.xml by configuring the spring-boot-maven-plugin:

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <image>
                    <name>foo/bar</name>
                </image>
                <builder>
                    <network>host</network>
                </builder>
            </configuration>
        </plugin>
    </plugins>
</build>

With this setup, you can just run mvn spring-boot:build-image and the network mode will automatically be set to host during the build.

Quick Note

This configuration applies only to the build phase (when the builder is pulling dependencies, running build steps, etc.)—it doesn't affect how the final image runs. Also, make sure you're using Spring Boot 2.4 or newer, since this property was introduced in that version.

内容的提问来源于stack exchange,提问作者Николай Беженар

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 07:59:05