[dockerfile] [solved] Directory '/' does not contain a Gradle build

Hello,

I want to put my kotlin-spring-boot project into container:

FROM alpine:3.19.1
COPY ./ /tmp
EXPOSE 8080
RUN apk add openjdk17 && \
    chmod +x ./tmp/gradlew && \
    ./tmp/gradlew build
ENTRYPOINT ./tmp/gradlew bootRun

,but during build:

$ docker build .

I get a failure on command ./tmp/gradlew build

Directory '/' does not contain a Gradle build.

By output in a console I see gradle has been downloaded successfully, so I don’t understand why docker doesn’t see it (and why does it point out on ‘/’ directory instead of ‘/tmp’?).

I tried to debug this by changing file in this way:

FROM alpine:3.19.1 as debug
COPY ./ /tmp
EXPOSE 8080
RUN apk add openjdk17
RUN chmod +x ./tmp/gradlew
FROM alpine:3.19.1 as next
RUN ./tmp/gradlew build
ENTRYPOINT ["echo", "hello world"]

and executing docker build -f Dockerfile --target debug --tag debug . (source)

It allowed me to run a shell docker run -it debug /bin/sh and execute all commands to check the image. I was able to run ./gradlew bootRun and deploy my application.

Could you help me please to figure out what is the issue with my initial image?

I have found a solution for this - explicitly tell the docker working directory WORKDIR /tmp

FROM alpine:3.19.1
COPY ./ /tmp
EXPOSE 8080
RUN apk add openjdk17
WORKDIR /tmp
RUN chmod +x ./gradlew
RUN ./gradlew build
ENTRYPOINT ["./gradlew", "bootRun"]

At the beginning the docker is able to recognize the direct path - gradlew command is started - but somewhere due execution it uses file path which is not existed, possibly it takes from the env variable which could be altered by WORKDIR.

If anyone has more detailed knowledge of docker, please share it here for future readers.