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?