Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I put the Dockerfile into the project root.

meaning there's a ./target directory and therein, maven generates a spring-boot-web-0.0.1-SNAPSHOT.jar file.

I now want to add that to a docker image:

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"]

This ADD fails:

ADD failed: stat /var/lib/docker/tmp/docker-builder119635304/myapp.jar: no such file or directory
like image 297
User1291 Avatar asked Oct 28 '25 05:10

User1291


1 Answers

The solution seems to be moving the comments to their own lines as they will break the commands if they're in the same line as them.

This Dockerfile works prefectly fine:

# 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"]
like image 50
User1291 Avatar answered Oct 29 '25 18:10

User1291