Docker中使用maven镜像,Dockerfile配置仓库地址
可以使用官方的maven镜像,并准备好配置好仓库地址的setting.xml文件
maven官方在DockerHub中给出的配置仓库的方法为:
Packaging a local repository with the image
The
$MAVEN_CONFIGdir (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.xmlwith the dependencies you need and use this in yourDockerfile./usr/share/maven/ref/settings-docker.xmlis 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/repositoryas local repo.COPY pom.xml /tmp/pom.xml RUN mvn -B -f /tmp/pom.xml -s /usr/share/maven/ref/settings-docker.xml dependency:resolveTo add your custom
settings.xmlfile to the image useCOPY settings.xml /usr/share/maven/ref/For an example, check the
testsdir
这里我们参考官方实例,通过Dockerfile COPY命令 配置仓库地址:
FROM maven:latest
WORKDIR /work/
COPY /settings.xml /root/.m2/settings.xml
RUN mvn clean install -DskipTests
RUN ls target
更多推荐
所有评论(0)