Use maven image in Docker, Dockerfile configure warehouse address

You can use the official maven mirror, and prepare the setting.xml file for configuring the warehouse address

The official method of configuring the warehouse given by maven in DockerHub is:

Packaging a local repository with the image

The $MAVEN_CONFIG dir (default to /root/.m2) could be configured as a volume so anything copied there in a Dockerfile at build time is lost. For that reason the dir /usr/share/maven/ref/ exists, and anything in that directory will be copied on container startup to $MAVEN_CONFIG.

To create a pre-packaged repository, create a pom.xml with the dependencies you need and use this in your Dockerfile/usr/share/maven/ref/settings-docker.xml is a settings file that changes the local repository to /usr/share/maven/ref/repository, but you can use your own settings file as long as it uses /usr/share/maven/ref/repository as local repo.

COPY pom.xml /tmp/pom.xml
RUN mvn -B -f /tmp/pom.xml -s /usr/share/maven/ref/settings-docker.xml dependency:resolve

To add your custom settings.xml file to the image use

COPY settings.xml /usr/share/maven/ref/

For an example, check the tests dir

Here we refer to the official example and configure the warehouse address through the Dockerfile COPY command:

FROM maven:latest
WORKDIR /work/
COPY /settings.xml /root/.m2/settings.xml
RUN  mvn clean install  -DskipTests
RUN  ls target

 

Guess you like

Origin blog.csdn.net/qq_14997473/article/details/112601931