Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
784 views
in Technique[技术] by (71.8m points)

linux - How do I point a docker image to my .m2 directory for running maven in docker on a mac?

When you look at the Dockerfile for a maven build it contains the line:

VOLUME /root/.m2

Now this would be great if this is where my .m2 repository was on my mac - but it isn't - it's in

/Users/myname/.m2

Now I could do:

But then the linux implementation in Docker wouldn't know to look there. I want to map the linux location to the mac location, and have that as part of my vagrant init. Kind of like:

ln /root/.m2 /Users/myname/.m2

My question is: How do I point a docker image to my .m2 directory for running maven in docker on a mac?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

To share the .m2 folder in build step you can overwrite the localRepository value in settings.xml.

Here is the Dockerfile snippet I used to share my local .m2 repository in docker.

FROM maven:3.5-jdk-8 as BUILD

RUN echo 
    "<settings xmlns='http://maven.apache.org/SETTINGS/1.0.0' 
    xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' 
    xsi:schemaLocation='http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd'> 
        <localRepository>/root/Users/myname/.m2/repository</localRepository> 
        <interactiveMode>true</interactiveMode> 
        <usePluginRegistry>false</usePluginRegistry> 
        <offline>false</offline> 
    </settings>" 
    > /usr/share/maven/conf/settings.xml;

COPY . /usr/src/app
RUN mvn --batch-mode -f /usr/src/app/pom.xml clean package

FROM openjdk:8-jre
EXPOSE 8080 5005
COPY --from=BUILD /usr/src/app/target /opt/target
WORKDIR /opt/target
ENV _JAVA_OPTIONS '-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005'
ENV swarm.http.port 8080

CMD ["java", "-jar", "app-swarm.jar"]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...