Using Docker 1.12. For some reason, when I build my Docker container which is a Gradle 2.14 project, it builds the fat JAR and stores it locally. The problem is that although I have a single fat JAR being stored in the Docker image, it creates 4 new layers each around 300MB.
Not sure why it requires so much space for a single file. How can I optimize this Dockerfile to prevent it in the future?
Should I be building the JAR outside the container and then copying it?
RUN mkdir /build
COPY . /build
RUN mkdir /app
RUN cp ./lib/machine-learning-models.jar /app/machine-learning-models.jar
RUN bash gradlew shadowJar
RUN cp ./build/libs/server-0.1-SNAPSHOT-all.jar /app/server.jar
RUN rm -rf /build
ENTRYPOINT java -cp /app/machine-learning-models.jar:/app/server.jar com.company.Boot
It appears the best solution is to just build the fat JAR outside the container and
My final solution uses a bare bones Docker Alpine container bundled with the Java JRE. At build time I run
gradle shadowJar and then copy the JAR into the container.
As per @mixja's response, it's essentially a "release" image.