gradle jar file with yml config file doesn't execute from dockerfile

Viewed 219

I want to run a gradle build inside a container, then execute the jar with its config file and server parameters. This is what I have

WORKDIR /app
COPY . /app


RUN  chmod +x gradlew  \
  && gradle build

COPY config/*.yml build/libs

RUN cd build/libs \
  && ls -la
  

EXPOSE 8081

ENTRYPOINT ["java", "-jar", "/app/build/libs/app.jar", "-Dconfig.location=app/build/libs/config.yml", "-Dgrails.env=prod"]

I can see that both the yml file and the jar file are in the build libs folder, but when I build the dockerfile, I get error indicating missing yml file. When I reorder them and place config location before the jar file, it finds the config, but doesn't execute the jar file. When I purposely put an incorrect path to jar file, I get an error that jar is not found.

What I get after docker run is

    Configuring Spring Security Core ...
... finished configuring Spring Security Core Configuring Spring Security REST 2.0.0.RC1...
... finished configuring Spring Security REST

And that's it. Although running locally I get "application running.." aswell. Any help appreciated!

1 Answers

I cannot post a comment as I am a newbie.

I see that you are in build/libs when you run-

RUN cd build/libs

Then your ENTRYPOINT command is using relative path for config location-

"-Dconfig.location=app/build/libs/config.yml"

You can try starting the location with "/app" instead of "app".

Also, if that doesn't help, can you paste the exact errors you are getting in the 2 scenarios you mentioned?

Related