I've been trying to create a multi-stage docker build for my spring-boot-application. The problem is on every change on the master branch, the pom.xml file changes (thanks to maven release plugin), so it's kind of hard to make use of docker build-cache during the build stage and all the dependencies will be downloaded every time I run the build. As far as I know, I can't mount volumes during the building of the image. The experimental version of the docker allows you to mount volumes during the build but it's still experimental so I'm trying to avoid it.
So I decided to try my luck with docker-compose, where the first service will run "mvn package" inside the container and create a jar file inside a shared volume, which will be then used by the second service to build its own image (basically adding that jar inside its image), which will be published to docker hub. Whatever I was trying to do didn't seem right. Now I'm not really expert of docker-compose here, but is this the right approach to do it?
I'm using Docker version 18.09.0, build 4d60db4
version: '3'
#Specify all the services you want to create
services:
#service name
build-service:
context: .
dockerfile: Dockerfile-build
volumes:
- ./:/usr/app
- "$(HOME)"/.m2:/usr/mvn/.m2
spring-app:
conext: .
dockerfile: Dockerfile-jar
volumes:
- ./:/usr/app
Is there any way to make use of local .m2 repository during the first stage. Or any other suggestions are welcome.