title: Java docker file. Build and test or just run jar file?
body: <p>I'm thinking this in a CI pipeline where I should first build and test my app and the result should be a docker image.</p>
  
  <p>I'm wondering if it's more common to build on the build server using the build environment and then running tests. Maybe using a build script for this. And lastly just add the jar file to the Docker container produced using COPY and then have Entrypoint java -jar .jar. So keep the Dockerfile very small, and have testing and building outside the container.</p>
  
  <p>A bit like this:</p>
  
  <pre><code>FROM openjdk:8-jre-alpine
  CMD java ${JAVA_OPTS} -jar *.jar
  COPY build/libs/*.jar .
  </code></pre>
  
  <p>Or if I should add all the source code to the container, build it and then run tests inside the container and then having the Entrypoint (as before) running the jar file that was produced? So keeping everything in the Dockerfile? Maybe doing some cleanup also, removing the source code</p>
  
  <p>This doesn't really have to be Java I guess, the same question applies to all languages</p>