spring - docker 运行-错误:无法访问jarfile

标签 spring maven docker dockerfile

我是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/

相关文章:

docker - 升级 Swarm 模式集群

java - 处理更改的 ENUM 定义 - 数据库

java - @ConfigurationProperties 注解的警告

maven - 如何在 pom 中获取 Maven testResources 目录

Maven 和原型(prototype)

java - 将 Selenium Java 项目转换为页面对象设计模式时出错

docker - kubectl : not found in WSL terminal

java - cvc-complex-type.2.4.c : The matching wildcard is strict, 但找不到元素 'mvc:annotation-driven' 的声明

Spring webSocket - 使用 IE8 拒绝基于用户权限的主题订阅 - 从未调用过确定用户()

docker - 无法在 Alpine 图像中使用 make