We run Jenkins pipeline on docker container. During the run, we mount host's .m2 to container's with -

-v $HOME/.m2:/usr/share/.m2

When host's .m2 mounted into container's /usr/share/.m2 maven build takes 4 times longer than usual. This is because everytime, it downloads artifacts even though those are present in host's .m2 repo.

But if mounting is changed to root's .m2 like following, maven build completes fast as it ignores artifacts which are already downloaded in host's .m2 repo -

-v $HOME/.m2:/root/.m2

This seems to have correct mounting.

Could you please help to understand why mounting to /usr/share/.m2 does fresh download and /root/.m2 works as expected by taking host's .m2 into consideration?

  • The maven docker image runs with a root user by default(the one available in hub) and it uses the /use/root/.m2 as local cache. Do you have a custom user ? Have you tried checking which m2 location the mvn command uses? What flags are you passing to the command? – Ram Kamath Mar 2 at 21:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.