一、前言
Google开源的Java容器化工具,可作为插件快速集成到项目中,构建镜像,实现 Java 应用容器化。
二、Jib插件构建镜像push到阿里云镜像仓库
2.1创建阿里云镜像仓库
阿里云镜像仓库地址:https://cr.console.aliyun.com/repository
成功后到基本信息中复制公网地址
pom文件中添加
<build>
<plugins>
<!-- Jib插件 -->
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>1.7.0</version>
<configuration>
<!-- 拉取所需的基础镜像 - 这里用于运行springboot项目 -->
<from>
<image>openjdk:alpine</image>
</from>
<!-- 最后生成的镜像配置 -->
<to>
<!-- push到阿里云镜像仓库-->
<image>
镜像仓库的公网地址
</image>
<!-- 镜像版本号 -->
<tags>
<tag>v1</tag>
</tags>
<auth>
<username>用户名</username>
<password>阿里云登录密码</password>
</auth>
</to>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
成功后
登录阿里云Docker Registry并拉取镜像,详细步骤根据操作指南中进行
docker run -d -p 本机端口访问:程序运行端口 --name 别名 镜像仓库公网地址:镜像版本