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

如何通过Spring Boot的build-image添加容器标签?

使用spring-boot-maven-plugin添加Docker镜像元数据标签

当使用spring-boot-maven-plugin的mvn spring-boot:build-image命令构建镜像时,你可以直接在插件配置中添加自定义元数据标签,无需编写Dockerfile,具体操作如下:

配置pom.xml

在项目的pom.xml里,找到spring-boot-maven-plugin的配置节点,通过<image><labels>子节点定义所需的元数据标签:

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <image>
                    <!-- 自定义镜像元数据标签 -->
                    <labels>
                        <label>title=My Spring Boot App</label>
                        <label>version=1.0.0-SNAPSHOT</label>
                        <label>authors=stewart</label>
                    </labels>
                </image>
            </configuration>
        </plugin>
    </plugins>
</build>

构建镜像

执行常规的镜像构建命令即可:

mvn spring-boot:build-image

验证标签

镜像构建完成后,使用和Dockerfile构建后相同的命令查看标签:

docker inspect --format='{{json .Config.Labels}}' my-spring-boot-image:latest

执行后就能看到你配置的title、version、authors等标签信息。

内容的提问来源于stack exchange,提问作者Stewart

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 06:32:33