搭建 Docker 本地仓库:https://www.cnblogs.com/jhxxb/p/13637834.html
Maven 配置,使用 jlb 插件
<finalName>ImageName</finalName> <!-- 多次构建后,清理积累的无用镜像:docker image prune --> <plugin> <groupId>com.google.cloud.tools</groupId> <artifactId>jib-maven-plugin</artifactId> <version>2.5.2</version> <configuration> <from> <!-- 使用本地 openjdk 镜像,tag 是 alpine --> <image>11.71.91.51:5000/openjdk:alpine</image> </from> <to> <!-- 推送至本地镜像仓库 --> <image>11.71.91.51:5000/${project.build.finalName}</image> <tags> <tag>${project.version}</tag> </tags> </to> <container> <mainClass>com.MainApplication</mainClass> <!-- jvm 内存参数 --> <jvmFlags> <jvmFlag>-Xms4g</jvmFlag> <jvmFlag>-Xmx4g</jvmFlag> </jvmFlags> <!-- 要暴露的端口 --> <ports> <port>8080</port> </ports> <args> <arg>--spring.profiles.active=dev</arg> </args> </container> <!-- 支持 http 协议连接镜像仓库 --> <allowInsecureRegistries>true</allowInsecureRegistries> </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>build</goal> </goals> </execution> </executions> </plugin>
执行 package 就会构建并推送了
https://blog.csdn.net/boling_cavalry/article/details/100179709
https://github.com/GoogleContainerTools/jib/tree/master/jib-maven-plugin#quickstart