1

When I try to build this Docker-Image, I get the following error:

Log

FROM java:8 WORKDIR /app ADD . /app EXPOSE 8080 RUN ./gradlew build CMD ./gradlew bootRun 

When I just build the app with "gradlew build" it runs and when I try to run this Docker Image with a Mac, it works too, just not for windows

EDIT:

RUN ls Image

6
  • No such file or directory... You need to actually copy over the gradlew shell script Commented May 29, 2018 at 12:52
  • can you elaborate on this a bit further? Commented May 29, 2018 at 12:53
  • 1
    Please show the content of the build directory in windows. Add a RUN ls step before the Gradle commands... My point is that ADD . /app did not actually ADD an executable file named ./gradlew, as the error says Commented May 29, 2018 at 12:57
  • edited it into the post Commented May 29, 2018 at 13:02
  • Hmm... Okay. Anyway, this not really a "proper" way to run a Java app. You typically build a JAR outside of the container, then copy it in and just run that Commented May 29, 2018 at 13:07

3 Answers 3

1

This is not a great answer, but what I found is that when Windows mounts files into Docker from Windows, it leaves Windows-like line endings on the mounted files. A janky way to solve it in your Dockerfile would be to install dos2unix in the container and add a

RUN dos2unix gradlew 

prior to executing your build process. Unfortunately, this is a TERRIBLE solution. Hopefully Docker for Windows on WSL2 that is supposed to release soon will solve this better but for now you are stuck with this janky solution.

Sign up to request clarification or add additional context in comments.

Comments

0

gradlew must be marked as executable.

chmod +x gradlew

Mac and Linux share permissions scheme but Windows needs to use a virtual FS so it copies files with default permissions - 644 and you need 755.

Comments

0

Worked for me, adding in the dockerfile, before RUN ./gradlew lib:build:

RUN apt-get update && \ apt-get install dos2unix && \ apt-get clean RUN dos2unix gradlew RUN chmod +x gradlew RUN ./gradlew lib:build 

Comments