I'm currently attempting to build a Spring Boot application using Docker. I executed the build command as follows:
docker build -t myapp:latest -f Dockerfile2 .
Below is the Dockerfile I've crafted for the build process:
FROM adoptopenjdk/openjdk11 as builder
WORKDIR /builder
COPY gradlew ./
COPY gradle ./gradle
COPY build.gradle ./
COPY settings.gradle ./
COPY src ./src
RUN chmod +x ./gradlew
RUN ./gradlew bootJar
FROM adoptopenjdk/openjdk11 as runner
WORKDIR /app
COPY --from=builder /builder/build/libs/app.jar ./
EXPOSE 8080
CMD ["java","-jar","-Dspring.profiles.active=local","app.jar"]
However, I'm encountering the following error during the build process:
/bin/sh: 1: ./gradlew: not found
below is full error response
[+] Building 0.4s (14/15) docker:default
=> [internal] load build definition from Dockerfile2 0.0s
=> => transferring dockerfile: 450B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/adoptopenjdk/openjdk11:latest 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 18.35kB 0.0s
=> [builder 1/9] FROM docker.io/adoptopenjdk/openjdk11 0.0s
=> CACHED [runner 2/3] WORKDIR /app 0.0s
=> CACHED [builder 2/9] WORKDIR /builder 0.0s
=> CACHED [builder 3/9] COPY gradlew ./ 0.0s
=> CACHED [builder 4/9] COPY gradle ./gradle 0.0s
=> CACHED [builder 5/9] COPY build.gradle ./ 0.0s
=> CACHED [builder 6/9] COPY settings.gradle ./ 0.0s
=> CACHED [builder 7/9] COPY src ./src 0.0s
=> CACHED [builder 8/9] RUN chmod +x ./gradlew 0.0s
=> ERROR [builder 9/9] RUN ./gradlew bootJar 0.3s
------
> [builder 9/9] RUN ./gradlew bootJar:
0.262 /bin/sh: 1: ./gradlew: not found
------
Dockerfile2:14
--------------------
12 | RUN chmod +x ./gradlew
13 |
14 | >>> RUN ./gradlew bootJar
15 |
16 | FROM adoptopenjdk/openjdk11 as runner
--------------------
ERROR: failed to solve: process "/bin/sh -c ./gradlew bootJar" did not complete successfully: exit code: 127
View build details: docker-desktop://dashboard/build/default/default/ut88drrrrlzvp10e5pnr6u1a4
Here are the steps I've taken to address this issue:
- Initially, I copied the gradlew file correctly within the Dockerfile and set permissions to execute.
- Then, I attempted to execute gradlew within the Docker image to perform necessary tasks. Additionally, I also tried executing chmod +x gradlew before running gradlew within the Docker image.
- As a troubleshooting step, I even tried removing gradlew to see if the build process would proceed differently.
Despite these efforts, I'm still facing this error. I'm eager to resolve this issue and get the build working correctly. Any assistance would be greatly appreciated.
Build Dashboard: ut88drrrrlzvp10e5pnr6u1a4