Docker中使用maven镜像,Dockerfile配置仓库地址

可以使用官方的maven镜像,并准备好配置好仓库地址的setting.xml文件

maven官方在DockerHub中给出的配置仓库的方法为:

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

这里我们参考官方实例,通过Dockerfile COPY命令 配置仓库地址:

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

猜你喜欢

转载自blog.csdn.net/qq_14997473/article/details/112601931