skip to Main Content

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


  1. 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.

    command overrides the default command declared by the container image (i.e. by Dockerfile’s CMD). 
    

    CMD

    The CMD instruction has three forms:

    CMD ["executable","param1","param2"] (exec form, this is the preferred form)
    CMD ["param1","param2"] (as default parameters to ENTRYPOINT)
    CMD command param1 param2 (shell form)
    

    There can only be one CMD instruction in a Dockerfile. If you list
    more than one CMD then only the last CMD will take effect.

    And I guess as gradle is a build tool it should be specified within the dockerfile.
    https://docs.docker.com/compose/compose-file/build/

    Login or Signup to reply.
  2. I’ve had similar issues when running stuff with ./hello-world in the terminal. Try changing the command to sh ./gradlew build.

    command: 'sh ./gradlew build'
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search