声明:本文CSDN作者原创投稿文章,未经许可禁止任何形式的转载,原文链接
前提
在使用Dockerfile构建镜像时,Maven的Docker镜像内置的是官方源,使用起来下载速度太慢,搜了一圈发现阿里在2016年做过阿里源的Maven的镜像但也仅有JDK7和8两个版本,网上博客内容也都琳琅满目,所以在此记录一下,本次使用的Maven镜像是maven:3.8.3-openjdk-11
。
操作
把带有国内源的settings.xml文件拷贝入Maven的Docker镜像内即可。
-
第一步:在Dockerfile同级目录下新建文件settings.xml,内容如下:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository/>
<interactiveMode/>
<usePluginRegistry/>
<offline/>
<pluginGroups/>
<servers/>
<mirrors>
<mirror>
<id>aliyunmaven</id>
<mirrorOf>central</mirrorOf>
<name>阿里云公共仓库</name>
<url>https://maven.aliyun.com/repository/central</url>
</mirror>
<mirror>
<id>repo1</id>
<mirrorOf>central</mirrorOf>
<name>central repo</name>
<url>http://repo1.maven.org/maven2/</url>
</mirror>
<mirror>
<id>aliyunmaven</id>
<mirrorOf>apache snapshots</mirrorOf>
<name>阿里云阿帕奇仓库</name>
<url>https://maven.aliyun.com/repository/apache-snapshots</url>
</mirror>
</mirrors>
<proxies/>
<activeProfiles/>
<profiles>
<profile>
<repositories>
<repository>
<id>aliyunmaven</id>
<name>aliyunmaven</name>
<url>https://maven.aliyun.com/repository/public</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>MavenCentral</id>
<url>http://repo1.maven.org/maven2/</url>
</repository>
<repository>
<id>aliyunmavenApache</id>
<url>https://maven.aliyun.com/repository/apache-snapshots</url>
</repository>
</repositories>
</profile>
</profiles>
</settings>
-
第二步:在Dockerfile中将上一步的settings.xml文件拷贝进入Maven的Docker镜像内部。
COPY settings.xml /usr/share/maven/conf/settings.xml
接下来下载依赖的操作都会从阿里云下来了。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)