2

I have to build a docker image and package java application using maven in the docker container but when I run the build process all is going fine but all maven dependencies downloading from maven remote repo.

That is my docker file:

FROM ubuntu_img
CMD ./mvnw -s .mvn/settings.xml --batch-mode clean package

How can I configure docker or maven for downloading dependencies from maven local repository located on my laptop?

4
  • Or you can package locally and add to container. Commented Oct 9, 2019 at 7:52
  • @pmverma no I have to run the maven build in the docker container because all tests have to be executed in the docker environment. Commented Oct 9, 2019 at 7:56
  • You can also map local m2 repo to container m2 repo in which case it won't download from remote. Commented Oct 9, 2019 at 8:02
  • With docker experimental features enabled and using buildkit you can mount a cache volume during the builds, check this answer. Commented Oct 9, 2019 at 8:14

2 Answers 2

3

At first, you need to attach the directory of your existing local Maven repository into the Docker container:

VOLUME ["/home/<user>/.m2", "/root/.m2"]

Then you need to tell Maven (inside your container) to use this directory as a local repository.

setting.xml

<settings ...>
    <localRepository>/root/.m2</localRepository>
    ...
</settings>
Sign up to request clarification or add additional context in comments.

8 Comments

where I should write VOLUME ["/home/<user>/.m2", "/root/.m2"] in my docker file?
You need to add 'VOLUME ...' into the docker-compose.yml file. More info here: blog.code4hire.com/2018/06/…
Can I mount the volume in docker file on build image step without docker-compose.yml file?
This is a different question. I think that, the best you can do is to complete this question then you can search for it on the Internet or ask a new question.
|
0

use volume,like this:

VOLUME ["/home/test/.m2", "/root/.m2"]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.