I am trying to mount a host directory with /root/.m2 directory in maven docker file. Purpose is to avoid downloading dependencies with each build. But somehow, maven is downloading dependencies with each docker build. I can see mapped host directory is empty.
Here is my Docker compose file:
version: "2"
services:
database:
build:
context: ./database
dockerfile: Dockerfile
ports:
- "1433:1433"
dynamodb-local:
image: amazon/dynamodb-local
ports:
- "8000:8000"
my-hub:
depends_on:
- "database"
- "dynamodb-local"
volumes:
- ./target/m2-repo:/root/.m2 #either this mapping is not working or mvn is not considering this directory for cache, so its downloading dependencies for each build.
- ./target/log:/opt/jboss/wildfly/standalone/log #this is working, I can see logs
build: ./my-hub
ports:
- "8080:8080"
Here is my Dockerfile for maven, its multi stage build file.
FROM maven:3.8.1-jdk-11 AS mvn-img
# Declaring expected volumes
VOLUME ["/root/.m2", "/opt/jboss/wildfly/standalone/log"]
COPY ./ /usr/src/my-hub
WORKDIR /usr/src/my-hub
#/root/.m2 volume mapping with host is not working, so its downloading the dependencies with each build.
RUN mvn clean package -DskipTests
FROM jboss/wildfly:24.0.0.Final
.
.
.
other part all working....
I have tried other ways like manually setting repo path using -Dmaven.repo.local. But not working, Please let me know if I am doing something wrong, and I don't know. Thank you.