spring-boot-maven-plugin 釋出映象至私服
阿新 • • 發佈:2022-04-11
前提條件
- 雲端有個私服
- 本地有 docker 環境,並配置了國內倉庫
- 可以上網(映象構建過程可能會從 github 下載檔案)
版本說明
- OS: Windows10
- jdk:openjdk-17
- spring-boot:2.6.6
- maven:3.8.4 (預設 spring-boot 專案搭建時的包裝版本)
使用步驟
docker 配置
{ "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>[email protected]</email> </publishRegistry> </docker> </configuration> </plugin> </plugins> </build>
打包釋出指令碼指令
// 如果 jar 包下載很慢的話,可以考慮修改 maven 配置
// 需要確保 jdk 環境與專案的 jdk 環境一致
.\mvnw spring-boot:build-image
開發可以偷懶
疑難問題
- 打包出錯
90% 都是網路問題,多 jdk 的話,檢查 jdk 環境;檢查 maven 配置;檢查本地 docker 的映象源配置與安全檢查配置。 - 釋出出錯
檢查 docker 倉庫安全檢查配置