Maven的Docker镜像二次打包,再次推送至Harbor中

之所以如此操作,主要原因是,官版的镜像中默认的setting.xml已内置好,不容易修改,
重新二次打包,可以指定我们自己的setting.xml配置,配置自己的私服地址以及解决默认Maven仓库国内下载速度慢的问题

一、创建操作目录

$ cd ~
$ mkdir -p dockerfiles/maven

二、创建 settings.xml 和 Dockerfile

$ cd dockerfiles/maven
$ touch settings.xml 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>/root/.m2localRepository>
    <pluginGroups>
    pluginGroups>
    <proxies>
    proxies>
    <servers>
        <server>
            <id>maven-publicid>
            <username>anonymoususername>
        server>
        <server>
            <id>maven-innerid>
            <username>testusername>
            <password>testpassword>
        server>
        <server>
            <id>maven-releasesid>
            <username>testusername>
            <password>testpassword>
        server>
        <server>
            <id>maven-snapshotsid>
            <username>testusername>
            <password>testpassword>
        server>
        <server>
            <id>docker-registryid>
            <username>testusername>
            <password>testpassword>
        server>
    servers>
    <mirrors>
        <mirror>
            <id>alimavenid>
            <name>aliyun mavenname>
            <url>http://maven.aliyun.com/nexus/content/groups/public/url>
            <mirrorOf>centralmirrorOf>
        mirror>

        
        <mirror>
            <id>alimavenid>
            <mirrorOf>*mirrorOf>
            <url>https://maven.aliyun.com/repository/centralurl>
        mirror>

        
        <mirror>
          <id>mirrorIdid>
          <mirrorOf>centralmirrorOf>
          <name>Human Readable Name name>
          <url>https://repo1.maven.org/maven2/url>
        mirror>

        
        <mirror>
          <id>alimavenid>
          <name>aliyun mavenname>
          <url>https://central.maven.org/maven2url>
          <mirrorOf>centralmirrorOf>
        mirror>

        
        <mirror>
          <id>alimavenid>
          <name>aliyun mavenname>
          <url>https://maven.aliyun.com/nexus/content/repositories/central/url>
          <mirrorOf>centralmirrorOf>
        mirror>

    mirrors>
    <profiles>
        <profile>
            <id>chenrise-outerid>
            <repositories>
                <repository>
                    <id>maven-publicid>
                    <name>Chenrise Maven Httpname>
                    <url>http://maven.test.com/repository/maven-public/url>
                    <layout>defaultlayout>
                    <releases>
                        <enabled>trueenabled>
                        <updatePolicy>alwaysupdatePolicy>
                        <checksumPolicy>warnchecksumPolicy>
                    releases>
                    <snapshots>
                        <enabled>trueenabled>
                        <updatePolicy>alwaysupdatePolicy>
                    snapshots>
                repository>
            repositories>
        profile>
        <profile>
            <id>chenrise-innerid>
            <repositories>
                <repository>
                    <id>maven-workid>
                    <name>Chenrise Maven Httpname>
                    <url>http://192.168.1.190:8081/repository/maven-public/url>

                    <layout>defaultlayout>
                    <releases>
                        <enabled>trueenabled>
                        <updatePolicy>alwaysupdatePolicy>
                        <checksumPolicy>warnchecksumPolicy>
                    releases>
                    <snapshots>
                        <enabled>trueenabled>
                        <updatePolicy>alwaysupdatePolicy>
                    snapshots>
                repository>
            repositories>
        profile>
    profiles>
    <activeProfiles>
        <activeProfile>chenrise-inneractiveProfile>

    activeProfiles>
settings>

编辑settings.xml,主要是对maven的repository与mirror进行配置,内容如下

四、编辑Dockerfile,

来源于 maven:3.6.0-jdk-8-alpine,把编写好的配置settings.xml复制到镜像内即可

FROM maven:3.6.0-jdk-8-alpine
COPY settings.xml /usr/share/maven/ref/

五、构建镜像

$ docker build -t maven:3.5-jdk-8 .

其中maven指的是自定义镜像中的 REPOSITORY
3.5-jdk-8指的是自定义镜像中的 TAG

Maven的Docker镜像二次打包,再次推送至Harbor中_第1张图片

六、查看镜像

$ docker image ls

在这里插入图片描述

七、将自定义的镜像推送到自己的harbor仓库

# 如服务器未登录过,需先使用以下命令登录后再推送
# $ docker login harbor.test.com
$ docker push harbor.test.com/jx-common/maven:3.5-jdk-8

八、使用自定义镜像

Maven的Docker镜像二次打包,再次推送至Harbor中_第2张图片

你可能感兴趣的:(maven,docker,java)