我试图将创建了Spring Boot的微服务推送到托管K8集群的ibm云,但是在启动时不断出现以下错误:
Error: Invalid or corrupt jarfile /app.jar
我的dockerfile:
FROM openjdk:8-jdk-alpine
VOLUME /tmp
ARG JAR_FILE
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
我的pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>projects</groupId>
<artifactId>mydb2jdbcproject</artifactId>
<version>1</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<java.version>1.8</java.version>
<spring-cloud.version>Dalston.SR4</spring-cloud.version>
<docker.image.prefix>springio</docker.image.prefix>
<app.name>mydb2jdbcproject</app.name>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.15.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>com.ibm.db2.jcc</groupId>
<artifactId>db2jcc4</artifactId>
<version>4.26.14</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.json</groupId>
<artifactId>javax.json-api</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>com.ibm.cloud</groupId>
<artifactId>ibm-cloud-spring-boot-service-bind</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.eclipse.microprofile.config</groupId>
<artifactId>microprofile-config-api</artifactId>
<version>1.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<repositories>
<repository>
<id>repo</id>
<url>file://${project.basedir}/lib</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.4.9</version>
<configuration>
<repository>${docker.image.prefix}/${project.artifactId}</repository>
<buildArgs>
<JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
</buildArgs>
</configuration>
</plugin>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<images>
<image>
<name>us.icr.io/rbs1/rbstest</name>
<build>
<from>adoptopenjdk/openjdk8-openj9</from>
<entryPoint>
<exec>
<arg>java</arg>
<arg>-jar</arg>
<arg>/${project.build.finalName}.jar</arg>
</exec>
</entryPoint>
<assembly>
<targetDir>/</targetDir>
<mode>dir</mode>
<descriptorRef>artifact</descriptorRef>
</assembly>
</build>
</image>
</images>
</configuration>
</plugin>
</plugins>
</build>
</project>'
我的事件日志:
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 9m10s default-scheduler Successfully assigned default/basic-deployment-768559cfc6-6fd2j to 10.144.195.59
Normal Created 8m15s (x4 over 9m) kubelet, 10.144.195.59 Created container
Normal Started 8m15s (x4 over 9m) kubelet, 10.144.195.59 Started container
Normal Pulling 7m35s (x5 over 9m8s) kubelet, 10.144.195.59 pulling image "------/---------"
Normal Pulled 7m34s (x5 over 9m) kubelet, 10.144.195.59 Successfully pulled image "--------/---------"
Warning BackOff 4m6s (x24 over 8m57s) kubelet, 10.144.195.59 Back-off restarting failed container
图像保存在docker存储库中,然后拉入群集。我已完全登录到docker和ibmcloud。每次容器重新启动6次,但始终不会成功。我跑
mvn package
每次构建docker映像之前,都要确保有可用的jar,并且该jar存放在名为mydb2jdbcproject-1的目标文件夹中。
答案 0 :(得分:1)
在Dockerfile中替换
COPY ${JAR_FILE} app.jar
使用
COPY ${JAR_FILE} /app.jar
答案 1 :(得分:0)
令人尴尬的是,我没有意识到我需要使用${JAR_FILE}
指向正确的jar文件。在确保将其定向到我的应用程序罐之后,所有这些都可以正常工作。谢谢!
在这里保管以防有人需要。