我是dockers的新手
我正在尝试在Mac上运行:
docker 运行eloomina1 / datacollector
返回:
Error: Unable to access jarfile dataCollector-0.0.1-SNAPSHOT.jar
我已经检查过,它不是该文件的权限。
我正在建立这样的形象:
docker build --build-arg JAR_FILE = dataCollector-0.0.1-SNAPSHOT.jar -t eloomina1 / datacollector。
我的dockerfile:
FROM adoptopenjdk/openjdk12:latest
MAINTAINER Shahar Wider <shahar@ttt.com>
VOLUME /tmp
ARG JAR_FILE
COPY target/${JAR_FILE} dataCollector.jar
ENTRYPOINT ["java","-jar","dataCollector-0.0.1-SNAPSHOT.jar"]
我的pom.xml:
<groupId>com.eloomina</groupId>
<artifactId>dataCollector</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>dataCollector</name>
<properties>
<java.version>12</java.version>
<spring-cloud.version>Greenwich.SR1</spring-cloud.version>
<docker.image.prefix>eloomina1</docker.image.prefix>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.4.10</version>
<executions>
<execution>
<id>default</id>
<goals>
<goal>build</goal>
<goal>push</goal>
</goals>
</execution>
</executions>
<configuration>
<repository>eloomina1/datacollector</repository>
<tag>${project.version}</tag>
<buildArgs>
<JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
</buildArgs>
</configuration>
</plugin>
</plugins>
</build>
我的文件系统:
├── Dockerfile
├── HELP.md
├── cd
├── dataCollector.log
├── mvnw
├── mvnw.cmd
├── pom.xml
├── src
└── target
├── dataCollector-0.0.1-SNAPSHOT-docker-info.jar
├── dataCollector-0.0.1-SNAPSHOT.jar
最佳答案
图像内的jar文件的名称为dataCollector.jar
,因为您使用了COPY
命令,如下所示:
COPY target/${JAR_FILE} dataCollector.jar
所以
ENTRYPOINT
应该是:ENTRYPOINT ["java","-jar","dataCollector.jar"]
关于spring - docker 运行-错误:无法访问jarfile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56924013/