Reputation: 133
FROM gradle:4.2.1-jdk8-alpine
WORKDIR /app
ADD --chown=gradle:gradle /app/producer /app
RUN ./gradlew build --stacktrace
Project Structure is as follows . It is a muti module project:
<code>
--springbootdocker (Root folder of project) <br>
--producer (Sub module Producer) <br>
-- Dockerfile (for Producer)<br>
--consumer (Sub module Consumer) <br>
-- Dockerfile (for Consumer)<br
</code>
This is the docker file.
While doing docker build: getting this error
failed to build: ADD failed: stat /var/lib/docker/tmp/docker-builder561553413/app/producer: no such file or directory
Upvotes: 1
Views: 8438
Reputation: 133
This is the dockerfile which is currently working without any error.
FROM gradle:4.10.0-jdk8-alpine AS build
COPY --chown=gradle:gradle . /home/gradle/src/producer
WORKDIR /home/gradle/src/producer
RUN gradle bootJar --no-daemon --stacktrace
FROM openjdk:8-jdk-alpine
ARG JAR_FILE=build/libs/*.jar
COPY --from=build /home/gradle/src/producer/build/libs/*.jar producer.jar
ENTRYPOINT ["java","-jar","/producer.jar"]
Upvotes: 2
Reputation: 3069
Here you have to fix a couple of things in your Dockerfile.
ADD
command
ADD
command requires two parameters <src> and <dest>
. So, you should provide producer
path from the host as src container path as dest. But in such cases recommended to use COPY
command.
COPY --chown=gradle:gradle producer /app/producer
RUN ./gradlew
It should be just gradle
and it's WORKDIR
should be /app/producer
. If not it'll fail and you'll get,
Failed to create parent directory '/app/.gradle' when creating directory
'/app/.gradle/4.2.1/fileHashes'
error when running gradle
command.
Because the WORKDIR /app
owns by user root
.
Recommend to divide RUN gradle build --stacktrace
as ENTRYPOINT
and CMD
.
Complete Dockerfile
FROM gradle:4.2.1-jdk8-alpine
WORKDIR /app
COPY --chown=gradle:gradle producer /app/producer
WORKDIR /app/producer
ENTRYPOINT ["gradle"]
CMD ["build", "--stacktrace"]
The partial output of docker build
Starting a Gradle Daemon (subsequent builds will be faster)
:buildEnvironment
------------------------------------------------------------
Root project
------------------------------------------------------------
classpath
No dependencies
BUILD SUCCESSFUL in 5s
1 actionable task: 1 executed
Upvotes: 2
Reputation: 818
ADDed files need to be under the directory where the docker build is being run from, so depending on your structure you probably want something like:
ADD myProject /app
Assuming you have a structure like:
Dockerfile
myProject/
Upvotes: 0