title: Gradle and Docker: How to run a Gradle build within Docker container?
body: <p>I have the following docker file that runs a <code>spring boot application</code>:</p>
  <pre><code># For Java 11, try this
  FROM adoptopenjdk/openjdk11:alpine-jre
  
  #
  ARG JAR_FILE=/build/libs/pokerstats-0.0.1-SNAPSHOT.jar
  
  #
  WORKDIR /opt/app
  
  #
  COPY ${JAR_FILE} app.jar
  
  #
  ENTRYPOINT [&quot;java&quot;,&quot;-jar&quot;,&quot;app.jar&quot;]
  </code></pre>
  <p>The issue is that currently I have to run <code>gradle clean build</code> on my host machine first to create the jar file on my local machine at path:</p>
  <pre><code>/build/libs/pokerstats-0.0.1-SNAPSHOT.jar
  </code></pre>
  <p>How can I put this <code>gradle clean build</code> into my docker file so that the build step is done <em>inside</em> the container?</p>
  <p><strong>edit:</strong></p>
  <p>I want the steps for a user to be:</p>
  <ol>
  <li>Clone my project from <code>github</code></li>
  <li>run <code>docker build -t pokerstats .</code> - which will do the gradle build</li>
  <li>run docker container run -d -p 8080:8080 pokerstats</li>
  </ol>
  <p>The user will clone my project from github - I then want them to be able to run the docker container without having to build the project with gradle first - I.e. I want the docker file to do the build and copy the jar into the container.</p>