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.
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.
A bit like this:
FROM openjdk:8-jre-alpine
CMD java ${JAVA_OPTS} -jar *.jar
COPY build/libs/*.jar .
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
This doesn't really have to be Java I guess, the same question applies to all languages