问题描述
我有一个 Spring boot 应用程序并使用 spotify 插件来Dockerize我的应用程序.所以,我将有一个像下面这样的 Dockerfile.
FROM jdk1.8:latest运行 mkdir -p/opt/servie复制目标/service.war/opt/serviceENV JAVA_OPTS="" \JAVA_ARGS=""CMD java ${JAVA_OPTS} -jar/opt/service/service.war ${JAVA_ARGS}
我遇到了 JIB,它看起来很酷.但是,努力让它发挥作用.
我在下面添加了 pom 条目.
<groupId>com.google.cloud.tools</groupId><artifactId>jib-maven-plugin</artifactId><version>0.9.6</version><配置><来自><image>jdk1.8:latest</image></来自><到><image>docker.hub.com/test/service</image></配置></插件>
mvn 编译 jib:build
我看到以下内容.
[INFO] 构建依赖层...[信息] 构建类层...[INFO] 构建资源层...
当我运行 docker 镜像时,它说 Jar 文件不存在.我有一个多模块 maven 项目,并希望在从父 pom 运行 mvn compile jib:build 时对多个模块进行 dockerize.对此有什么帮助吗?
确实如此.JIB 不需要 Dockerfile
或 dockerd
.
下面分享一个例子,你可以把它复制到你的 pom.xml
的 plugins
部分
<groupId>com.google.cloud.tools</groupId><artifactId>jib-maven-plugin</artifactId><version>0.9.7</version><配置><allowInsecureRegistries>true</allowInsecureRegistries><来自><image>gcr.io/distroless/java</image></来自><到><!-- 确保您已经在 Google Cloud Platform 上创建了一个项目,请参阅 https://cloud.google.com/container-registry/--><image>gcr.io/my-gcp-project/${project.artifactId}:${project.version}</image><credHelper>gcr</credHelper><容器><jvmFlags><jvmFlag>-Xms256m</jvmFlag><jvmFlag>-Xmx512m</jvmFlag><jvmFlag>-Xdebug</jvmFlag><jvmFlag>-XX:+UnlockExperimentalVMOptions</jvmFlag><jvmFlag>-XX:+UseCGroupMemoryLimitForHeap</jvmFlag></jvmFlags><mainClass>learnmake.microservices.RunApplication</mainClass><端口>8080</端口><!-- <端口>4000-4004/udp</端口>--></端口><format>OCI</format><!-- OR <format>Docker</format>--><useCurrentTimestamp>true</useCurrentTimestamp></容器></配置></插件>
有关更详细的示例,请参阅learnmake-microservices
I have a Spring boot Application and using spotify plugin to Dockerize my application.So, I will have a Dockerfile like the below one.
FROM jdk1.8:latest
RUN mkdir -p /opt/servie
COPY target/service.war /opt/service
ENV JAVA_OPTS="" \
JAVA_ARGS=""
CMD java ${JAVA_OPTS} -jar /opt/service/service.war ${JAVA_ARGS}
I came across JIB and it looks really cool. But, struggling to get it working.
I added the pom entry below.
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>0.9.6</version>
<configuration>
<from>
<image>jdk1.8:latest</image>
</from>
<to>
<image>docker.hub.com/test/service</image>
</to>
</configuration>
</plugin>
I see the following.
[INFO] Building dependencies layer...[INFO] Building classes layer...[INFO] Building resources layer...
When i run the docker image, it says, Jar file does not exist. I have a multi module maven project and would like to dockerize multiple module on running mvn compile jib:build from the parent pom. Any help on this?
Yes indeed. JIB doesn't need Dockerfile
or dockerd
.
Sharing an example below, you can just copy it into plugins
section of your pom.xml
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>0.9.7</version>
<configuration>
<allowInsecureRegistries>true</allowInsecureRegistries>
<from>
<image>gcr.io/distroless/java</image>
</from>
<to>
<!-- make sure you already have created a project at Google Cloud Platform, see https://cloud.google.com/container-registry/ -->
<image>gcr.io/my-gcp-project/${project.artifactId}:${project.version}</image>
<credHelper>gcr</credHelper>
</to>
<container>
<jvmFlags>
<jvmFlag>-Xms256m</jvmFlag>
<jvmFlag>-Xmx512m</jvmFlag>
<jvmFlag>-Xdebug</jvmFlag>
<jvmFlag>-XX:+UnlockExperimentalVMOptions</jvmFlag>
<jvmFlag>-XX:+UseCGroupMemoryLimitForHeap</jvmFlag>
</jvmFlags>
<mainClass>learnmake.microservices.RunApplication</mainClass>
<ports>
<port>8080</port>
<!-- <port>4000-4004/udp</port> -->
</ports>
<format>OCI</format>
<!-- OR <format>Docker</format> -->
<useCurrentTimestamp>true</useCurrentTimestamp>
</container>
</configuration>
</plugin>
for more detailed example, see learnmake-microservices
这篇关于使用 JIB 插件 Dockerizing 多模块 Spring Boot 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!