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

如何配置Spring Boot Native Image构建Docker镜像的名称与版本?

修改Spring Boot Native构建镜像的名称和版本配置方式

你可以通过两种方式自定义Docker镜像的名称和版本:

1. 在pom.xml中永久配置

找到已引入的native-maven-plugin,添加<configuration>节点并指定imageName参数,格式为[镜像名称]:[版本号],示例如下:

<plugin>
    <groupId>org.graalvm.buildtools</groupId>
    <artifactId>native-maven-plugin</artifactId>
    <version>${native.maven.plugin.version}</version>
    <extensions>true</extensions>
    <executions>
        <execution>
            <id>build-native</id>
            <goals>
                <goal>build</goal>
            </goals>
            <phase>package</phase>
        </execution>
    </executions>
    <configuration>
        <!-- 自定义镜像名和版本,比如这里设置为my-native-app:1.0.0 -->
        <imageName>my-native-app:1.0.0</imageName>
    </configuration>
</plugin>

配置完成后,执行原命令mvn -Pnative spring-boot:build-image,生成的镜像就会使用你指定的名称和版本。如果只写镜像名不指定版本,默认会打上latest标签。

2. 命令行临时指定

如果只是临时调整镜像信息,不需要修改pom.xml,直接在命令中通过-Dspring-boot.build-image.imageName参数指定即可:

mvn -Pnative spring-boot:build-image -Dspring-boot.build-image.imageName=my-temp-app:2.0.0

这种方式优先级高于pom.xml中的配置,适合单次构建的临时需求。

内容的提问来源于stack exchange,提问作者Đỗ Như Vỹ

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.11 11:26:02