spring-boot-maven-plugin 发布镜像至私服

前提条件

  1. 云端有个私服
  2. 本地有 docker 环境,并配置了国内仓库
  3. 可以上网(镜像构建过程可能会从 github 下载文件)

版本说明

  • OS: Windows10
  • jdk:openjdk-17
  • spring-boot:2.6.6
  • maven:3.8.4 (默认 spring-boot 项目搭建时的包装版本)

使用步骤

docker 配置

image

{
"builder": {
"gc": {
"defaultKeepStorage": "20GB",
"enabled": true
}
},
"experimental": false,
"features": {
"buildkit": true
},
"registry-mirrors": [
"http://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn"
],
"insecure-registries": [
"如果私服使用的证书没有经过备份,则需要添加忽略安全检查仓库配置,例如:127.0.0.1:9990"
]
}

项目 pom.xml 文件

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!--热刷新资源-->
<addResources>true</addResources>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
<image>
<name>私服项目名称/${project.artifactId}:${project.version}</name>
<publish>true</publish>
</image>
<docker>
<publishRegistry>
<username>私服账号</username>
<password>私服密码</password>
<url>docker私服地址</url>
<email>dewen.jiang@chinacreator.com</email>
</publishRegistry>
</docker>
</configuration>
</plugin>
</plugins>
</build>

打包发布脚本指令

// 如果 jar 包下载很慢的话,可以考虑修改 maven 配置
// 需要确保 jdk 环境与项目的 jdk 环境一致
.\mvnw spring-boot:build-image

开发可以偷懒
image

疑难问题

  1. 打包出错
    90% 都是网络问题,多 jdk 的话,检查 jdk 环境;检查 maven 配置;检查本地 docker 的镜像源配置与安全检查配置。
  2. 发布出错
    检查 docker 仓库安全检查配置

参考网址

spring-boot-maven-plugin
docker reference

posted @   临渊不羡渔  阅读(395)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示