WildDev
WildDev

Reputation: 2367

Docker Cloud automated builds - no such file or directory

Running a build of Maven based project but it fails.

The reason is no such file or directory when it tries to find the jar.

Dockerfile:

FROM frolvlad/alpine-oraclejdk8:slim
FROM maven:3.5.2-jdk-8-slim
VOLUME /tmp
CMD ['mvn package']
ADD target/app-0.1.0-SNAPSHOT.jar app.jar <-- fails there
RUN sh -c 'touch /app.jar'
ENV JAVA_OPTS=""
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]

The log output:

...
Removing intermediate container 60da937dde8a
Step 4/8 : CMD ['mvn package']
---> Running in 8ba364ba9d98
---> 4a722569d1a7
Removing intermediate container 8ba364ba9d98
Step 5/8 : ADD target/app-0.1.0-SNAPSHOT.jar app.jar
ADD failed: stat /var/lib/docker/tmp/docker-builder1534563/target/app-0.1.0-SNAPSHOT.jar: no such file or directory
ERROR: Build failed: ADD failed: stat /var/lib/docker/tmp/docker-builder1534563/target/app-0.1.0-SNAPSHOT.jar: no such file or directory
ERROR: Build failed with exit code 2

Have played with the different settings but it still doesn't work despite the app name is matches to the built jar one.

How to fix the issue?

Upvotes: 1

Views: 221

Answers (1)

Mark Bramnik
Mark Bramnik

Reputation: 42531

This question IMO has nothing to do with Spring Boot, and it's Docker related. In general please share more information about how exactly you run docker build command, from which directory and where does your Dockerfile reside exactly. Without this information we can only speculate and provide generic answers:

To provide some points for consideration: Docker knows nothing about Maven structure of your project so you can just maintain the following layout:

 <some_dir>
  |____ Dockerfile
  |____ app-0.1.0-SNAPSHOT.jar

Then you can run the docker build command from this directory and this should work. Then you can experiment with target directory and once you'll understand when it works and when it doesn't proceed with your current folders layout, the chances that with this practice you'll find out the answer very quickly.

Upvotes: 2

Related Questions