John
John

Reputation: 1611

How to build docker image with maven?

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?

Upvotes: 2

Views: 1085

Answers (2)

zappee
zappee

Reputation: 22746

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>

Upvotes: 3

Willing
Willing

Reputation: 76

use volume,like this:

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

Upvotes: 0

Related Questions