Docker环境搭建 - Docker安装Maven私服Nexus3

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/gongm24/article/details/86358708

Docker 安装 Nexus3 及配置

环境

在 Centos7 的虚拟机上进行安装,虚拟机 IP 为 192.168.247.129

安装

拉取镜像

docker pull sonatype/nexus3 

查看镜像

docker images

运行容器

docker run -d --name nexus3 -p 8081:8081 -v /nexus-data:/nexus-data sonatype/nexus3

访问 Nexus3 首页 http://192.168.247.129:8081,使用 admin / admin123 进行登录

Nexus 的仓库分为这么几类:

  • hosted 宿主仓库:主要用于部署无法从公共仓库获取的构件(如 oracle 的 JDBC 驱动)以及自己或第三方的项目构件;
  • proxy 代理仓库:代理公共的远程仓库;
  • virtual 虚拟仓库:用于适配 Maven 1;
  • group 仓库组:Nexus 通过仓库组的概念统一管理多个仓库,这样我们在项目中直接请求仓库组即可请求到仓库组管理的多个仓库。

配置 Maven 使用 Nexus 私服

对 Maven 配置文件 settings.xml 进行配置

配置私服镜像

<mirrors>
    <mirror>
        <id>central</id>
        <mirrorOf>*</mirrorOf> <!-- * 表示让所有仓库使用该镜像-->
        <name>central-mirror</name>
        <url>http://192.168.247.129:8081/repository/maven-public/</url>
    </mirror>
</mirrors>

mirrorOf 表示代理的镜像," * " 表示将 Nexus 配置成所有仓库的镜像,central 表示将 Nexus 配置成中央仓库的镜像

配置阿里云仓库代理中央仓库,Nexus 代理其它仓库

<mirror>
    <id>nexus-aliyun</id>
    <name>Nexus aliyun</name>
    <url>http://maven.aliyun.com/nexus/content/groups/public</url>
    <mirrorOf>central</mirrorOf>
</mirror>
<mirror>
    <id>nexus</id>
    <mirrorOf>*</mirrorOf>
    <url>http://192.168.247.129:8081/repository/maven-public/</url>
</mirror>

配置 Nexus 作为快照仓库

<profiles>
    <profile>
        <id>nexus-resp</id>
        <repositories>
            <repository>
                <id>nexus-releases</id>
                <url>http://192.168.247.129:8081/repository/maven-releases/</url>
                <releases><enabled>true</enabled></releases>
                <snapshots><enabled>false</enabled></snapshots>
            </repository>
            <repository>
                <id>nexus-snapshots</id>
                <url>http://192.168.247.129:8081/repository/maven-snapshots/</url>
                <releases><enabled>false</enabled></releases>
                <snapshots><enabled>true</enabled></snapshots>
            </repository>
        </repositories>
    
        <pluginRepositories>
            <pluginRepository>
                <id>nexus-plugin</id>
                <url>http://192.168.247.129:8081/repository/maven-public/</url>
                <releases><enabled>true</enabled></releases>
                <snapshots><enabled>false</enabled></snapshots>
            </pluginRepository>
        </pluginRepositories>
    </profile>
</profiles>

<activeProfiles>
    <activeProfile>nexus-resp</activeProfile>
</activeProfiles>

配置完成,本地 Maven 项目就可以从 Nexus 私服拉取项目依赖。

将本地项目打包至私服

配置上传帐户密码(配置在Maven的配置文件 settings.xml 中)

<server>
    <id>nexus-releases</id>
    <username>admin</username>
    <password>admin123</password>
</server>
<server>
    <id>nexus-snapshots</id>
    <username>admin</username>
    <password>admin123</password>
</server>

配置部署发布版及快照版(配置在项目的 pom 文件中)

<distributionManagement>
    <repository>
        <id>nexus-release</id>
        <url>http://localhost:8081/repository/maven-public/</url>
    </repository>
    <snapshotRepository>
        <id>nexus-snapshots</id>
        <url>http://localhost:8081/repository/maven-snapshots/</url>
    </snapshotRepository>
</distributionManagement>

配置完成,本地项目执行 deploy 时,就会上传至 Nexus 私服。

猜你喜欢

转载自blog.csdn.net/gongm24/article/details/86358708