猿问

添加失败:stat /var/lib/docker/tmp/docker-builder

我在尝试从 openjdk 基础映像创建 docker 映像时遇到以下问题。


ADD ${JAR_FILE} websocket-demo.jar

ADD failed: stat /var/lib/docker/tmp/docker-builder673702145/target/websocket-demo-0.0.1-SNAPSHOT.jar: no such file or directory

实际上,我正在关注本教程并在尝试编译 Docker 文件时遇到了这个问题。


这是我的 docker 文件:


# Start with a base image containing Java runtime

FROM openjdk:8-jdk-alpine


# Add Maintainer Info

LABEL maintainer="Nuibb<*****@gmail.com>"


# Add a volume pointing to /tmp

VOLUME /tmp


# Make port 8080 available to the world outside this container

EXPOSE 8080


# The application's jar file

ARG JAR_FILE=target/websocket-demo-0.0.1-SNAPSHOT.jar


# Add the application's jar to the container

ADD ${JAR_FILE} websocket-demo.jar


# Run the jar file 

ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/websocket-demo.jar"]

你能告诉我如何解决这个问题吗?


ITMISS
浏览 1442回答 3
3回答

慕勒3428872

如果其他人遇到这个问题并且犯了像我这样的非常业余的错误,我正在写这个答案。我遇到这个问题是因为我<packaging>war</packaging>在我的 pom.xml 中,并试图在我的 docker 上下文中添加一个 jar 文件,其中包含这样的行(ADD ${JAR_FILE} xxx-xxx.jar)。因此,更改 pom.xml 文件中的行来<packaging>jar</packaging>为我完成此操作的简单修复&nbsp;。

斯蒂芬大帝

请尝试通过我认为创建 .jar 的路径 (build/libs) 指定 jar 文件因此,将您的代码更改为&nbsp; &nbsp; # Start with a base image containing Java runtimeFROM openjdk:8-jdk-alpine# Add Maintainer InfoLABEL maintainer="Nuibb<*****@gmail.com>"# Add a volume pointing to /tmpVOLUME /tmp# Make port 8080 available to the world outside this containerEXPOSE 8080# The application's jar fileARG JAR_FILE=build/libs/websocket-demo-0.0.1-SNAPSHOT.jar# Add the application's jar to the containerADD ${JAR_FILE} websocket-demo-0.0.1-SNAPSHOT.jar# Run the jar file&nbsp;ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/websocket-demo-0.0.1-SNAPSHOT.jar"]
随时随地看视频慕课网APP

相关分类

Java
我要回答