将Maven的Docker镜像修改为国内源

声明:本文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
    

    接下来下载依赖的操作都会从阿里云下来了。

  • 6
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值