缓存基于Maven的Docker构建的Jar依赖项

前端之家收集整理的这篇文章主要介绍了缓存基于Maven的Docker构建的Jar依赖项前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在从这个Dockerfile构建一个Docker镜像:

FROM maven:3.3.3-jdk-8
MAINTAINER Mickael BARON  

ADD pom.xml /work/pom.xml
WORKDIR /work
RUN mvn dependency:go-offline --fail-never

ADD ["src","/work/src"]
RUN ["mvn","package"]

使用这个Dockerfile,我强制在打包Java项目之前下载依赖项.因此,每次从src目录更改文件时,我都不必重新下载依赖项.

但是,有一个问题,这个问题取决于Maven的版本(基本图像).实际上,下载了依赖项,但它们不会持久保存到容器的〜/ .m2目录中.它是空的.因此,当我更改一些源文件时,所有依赖项都被重载.

但是,我注意到如果我从基本图像更改Maven的版本(例如FROM maven:3.2.5-jdk-8),它就可以了.

很奇怪,不是吗?

有关此主题的新指令:
https://github.com/carlossg/docker-maven#packaging-a-local-repository-with-the-image

The $MAVEN_CONFIG dir (default to /root/.m2) is configured as a volume so anything copied there in a Dockerfile at build time is lost. For that the dir /usr/share/maven/ref/ is created,and anything in there 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.

原文链接:https://www.f2er.com/docker/436668.html

猜你在找的Docker相关文章