添加失败:stat /var/lib/docker/tmp/docker-builderXYZ/myapp.jar:没有这样的文件或目录

时间:2019-04-09 07:33:53

标签: java maven spring-boot docker

我将Dockerfile放入项目根目录。

意味着有一个./target目录,并且maven在其中生成一个spring-boot-web-0.0.1-SNAPSHOT.jar文件。

我现在要将其添加到Docker映像中:

FROM centos

RUN yum install -y java    # `-y` defaults questions to 'yes'

VOLUME /tmp                # where Spring Boot will store temporary files

WORKDIR /                  # self-explanatory

ADD /target/spring-boot-web-0.0.1-SNAPSHOT.jar myapp.jar # add fat jar as "myapp.jar"

RUN sh -c 'touch ./myapp.jar' # updates dates on the application (important for caching)

EXPOSE 8080                # provide a hook into the webapp

# run the application; the `urandom` gets tomcat to start faster
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/myapp.jar"]

ADD失败:

ADD failed: stat /var/lib/docker/tmp/docker-builder119635304/myapp.jar: no such file or directory

1 个答案:

答案 0 :(得分:1)

解决方案似乎是将注释移到自己的行,因为如果它们与命令在同一行,它们将破坏命令。

Dockerfile非常好用:

# a linux runtime environment
FROM centos

# install java; `-y` defaults questions to 'yes'
RUN yum install -y java

# where Spring Boot will store temporary files
VOLUME /tmp

# self-explanatory
WORKDIR /

# add fat jar as "myapp.jar"
ADD /target/spring-boot-web-0.0.1-SNAPSHOT.jar myapp.jar

# updates dates on the application (important for caching)
RUN sh -c 'touch ./myapp.jar'

# provide a hook into the webapp
EXPOSE 8080

# run the application; the `urandom` gets tomcat to start faster
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/myapp.jar"]