【问题标题】:docker run - Error: Unable to access jarfiledocker run - 错误:无法访问 jarfile
【发布时间】:2019-11-17 07:47:54
【问题描述】:

我是码头工人的新手 我正在尝试在我的 Mac 上运行:

docker run eloomina1/datacollector

返回:

错误:无法访问 jarfile dataCollector-0.0.1-SNAPSHOT.jar

我已经检查过了,这不是文件的权限。 我正在构建这样的图像:

docker build --build-arg JAR_FILE=dataCollector-0.0.1-SNAPSHOT.jar -t eloomina1/datacollector .

我的码头文件:


    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

【问题讨论】:

  • 您可以通过运行docker run --rm -it --entrypoint /bin/sh eloomina1/datacollector 在您构建的镜像中获得一个调试shell。你在那里看到什么文件?你能把它和你的 Dockerfile 匹配起来吗?

标签: spring maven docker dockerfile


【解决方案1】:

图像中的 jar 文件的名称是 dataCollector.jar,因为您使用了这样的 COPY 命令:

COPY target/${JAR_FILE} dataCollector.jar

所以ENTRYPOINT 应该是:

ENTRYPOINT ["java","-jar","dataCollector.jar"]

【讨论】:

    猜你喜欢
    • 2019-06-03
    • 2018-12-17
    • 1970-01-01
    • 1970-01-01
    • 2021-01-22
    • 1970-01-01
    • 2018-11-07
    • 2020-12-01
    • 2017-04-13
    相关资源
    最近更新 更多