springboot2.0使用google的jib打包镜像上传阿里云
springboot2.x相关配置
1.服务的dockerfile配置
FROM frolvlad/alpine-oraclejdk8:slim
VOLUME /tmp
ADD triumph-service-eureka.jar app.jar
RUN bash -c 'touch /app.jar'
EXPOSE 8761
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
2.pom相关依赖的引入
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>1.1.2</version>
<configuration>
<from>
<!--打包的基本镜像 这个通过阿里云关联github构建基本镜像 如果是私有的话 需要添加账户密码-->
<image>registry.cn-hangzhou.aliyuncs.com/hukaijia/jib:1.0</image>
</from>
<to>
<!--打包生成的镜像 私有的话 需要账号密码-->
<image>registry.cn-hangzhou.aliyuncs.com/hukaijia/eureka:1.0.0</image>
<auth>
<username>xxxxxxxxxx@qq.com</username>
<password>xxxxxxxxxxxxxx.110</password>
</auth>
</to>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</configuration>
</plugin>
一些基本参数的解答
from:拉取的镜像的配置,默认为gcr.io/distroless/java
to:要生成的镜像的配置
image:拉取或生成的镜像名称
auth: 认证信息,分别为用户名和密码
<!-- 下面四个基本用不到,上面四个足以 -->
container: 容器的属性
jvmFlgs: JVM 容器的参数,和 Dockerfile 的 ENTRYPOINT作用相同
mainClass: 启动类限定名
args: main 方法的传入参数
ports: 容器暴露的端口,和 Dockerfile 的EXPOSE作用相同
github相关配置
1.创建 Repositories
只需要创建一个Dockerfile 通过阿里云关联构建基本镜像
阿里云相关配置
1.创建基本镜像
2.关联github
3.做基本镜像
生成基本镜像地址:
registry.cn-hangzhou.aliyuncs.com/hukaijia/jib:1.0
对应pom中的:
<from>
<!--打包的基本镜像 这个通过阿里云关联github构建基本镜像 如果是私有的话 需要添加账户密码-->
<image>registry.cn-hangzhou.aliyuncs.com/hukaijia/jib:1.0</image>
</from>
4.构建镜像
对应pom:
<to>
<!--打包生成的镜像 私有的话 需要账号密码-->
<image>registry.cn-hangzhou.aliyuncs.com/hukaijia/eureka:1.0.0</image>
<auth>
<username>xxxxxxxxxx@qq.com</username>
<password>xxxxxxxxxxxxxx.110</password>
</auth>
</to>
5.构建本地镜像推动到阿里云
mvn clean -P dev(分支) compile jib:build