I have this small build:
FROM eclipse-temurin:17-jdk as build-java
COPY java-project /root/project
WORKDIR /root/project
RUN chmod +x ./gradlew
RUN ls
RUN ./gradlew ...
#9 [build-build-java 5/6] RUN ls
#9 sha256:2d05b1e31ea4eaa8a9343b4f48fadcf7351b9d55dcc9c27e572d7bb32c4d723c
#9 0.194 build
#9 0.194 build.gradle
#9 0.194 docker-compose.yml
#9 0.194 gradle
#9 0.194 gradlew
#9 0.194 gradlew.bat
#9 0.194 HELP.md
#9 0.194 lombok.config
#9 0.194 settings.gradle
#9 0.194 src
#9 DONE 0.2s
#10 [build-build-java 6/6] RUN ./gradlew ...
#10 sha256:62cb4a1a6288008f3faccc3504e63ef87d30c3d7fde904a0576ffcf571e9b310
#10 0.310 /bin/sh: 1: ./gradlew: not found
#10 ERROR: executor failed running [/bin/sh -c ./gradlew ...]: exit code: 127
I’ve bene stuck on this for a while now.
I’ve tried using FROM gradle
instead and then using gradle ...
but then I get this file mount error:
#10 sha256:26de7798a76971c3eb12e6398f830ee487fe41c110d0f8ca6a23a92ee5437267
#10 0.854
#10 0.854 Welcome to Gradle 7.3.3!
#10 0.854
#10 0.854 Here are the highlights of this release:
#10 0.854 - Easily declare new test suites in Java projects
#10 0.855 - Support for Java 17
#10 0.855 - Support for Scala 3
#10 0.855
#10 0.855 For more details see https://docs.gradle.org/7.3.3/release-notes.html
#10 0.855
#10 0.952 Starting a Gradle Daemon (subsequent builds will be faster)
#10 2.153 Unable to list file systems to check whether they can be watched. Assuming all file systems can be watched. Re
ason: Could not query file systems: could not open mount file (errno 2: No such file or directory)
5
Answers
/bin/sh: 1: ./gradlew: not found
is usually caused by carriage return (r
) line endings in the bash script. Removing the carriage return will most like resolve the issue.Got exact same problem on Windows environment. This has to do with the line endings of the shell script files.
I fixed it this way:
Delete the git repo and re-clone it using the updated configuration
Relaunch the docker build
NB! just setting the configuration without re-cloning the repo doesn’t help.
I was having the same problem with the Windows environment. This happens according to carriage return (
r
) line endings in the bash script as @thokuest pointed out. But you should consider when you changed the line ending toLF
fromCLRF
in IntelliJ, thegradlew
file in the container is not changed accordingly and it is cached from your previousdocker build .
command. So you should run this command:docker build --no-cache .
or:
docker build --no-cache --progress=plain .
if you want to see full output.Converting EOL to UNIX (LF) of the gradlew file should work.
It can be fixed using notepad++.
Open the gradlew file in notepad++
Edit -> EOL Conversion -> UNIX (LF)
save
You need to run dos2unix command like below
And then don’t forget to run the docker build with –no-cache, to avoid picking layer caches from your previous
docker build
like below