I’m trying to execute a command inside a docker-compose file
services:
jar-build:
image: myImage
working_dir: /opt/build
volumes:
- "../:/opt/build/"
command: "./gradlew build"
running docker-compose -f aboveFile.yaml run jar-build
returns
exec ./gradlew: no such file or directory
however if I change the command to be a simple ls
services:
jar-build:
image: myImage
working_dir: /opt/build
volumes:
- "../:/opt/build/"
command: "ls"
I get
Dockerfile
build.gradle
docker
gradle
gradle.properties
gradlew
gradlew.bat
jfrog.gradle
lombok.config
settings.gradle
src
Why can it not find the gradlew file even though ls
shows it as there?
A whoami
commands shows I am root
gradlew is a shell script
I am using docker for windows with git bash and it is a linux container
edit: the first line of the gradlew file is #!/bin/sh
running the command echo $SHELL
returns (I did not copy incorrectly)
C:Program FilesGitusrbinbash.exe
edit2: gradlew and the build.yaml are LF endings
edit3: I’m not entirely sure what I did here. I re-cloned our repository a few times which may have cleared some cache somewhere. I also ran git config --global core.autocrlf input
and restarted but the mysterious error is gone and now I’m left with Could not connect to the Gradle daemon.
which sucks for me, but isn’t the target for this question.
2
Answers
It’s just a feeling looking over it, but docker compose is trying to execute the gradle build command within the docker container (where it is not located), not from your system.
And I guess as gradle is a build tool it should be specified within the dockerfile.
https://docs.docker.com/compose/compose-file/build/
I’ve had similar issues when running stuff with
./hello-world
in the terminal. Try changing the command tosh ./gradlew build
.