Docker环境搭建 - Docker安装Maven私服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 私服。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • --画作《犹大之吻》欣赏 作者:〔意大利〕 乔托 (Giotto di Bondone)收藏:帕多瓦的斯克罗威尼礼...
    努力找自己的魏天天阅读 549评论 0 0
  • 二月的尾巴阳光依旧很耀眼 天气依旧忽冷忽热变幻不定 前一天还高高挽起来的头发 第二天就要全部塞进围巾里 我也知道你...
    望天的蝈蝈阅读 147评论 0 0
  • 就跟质疑婚姻存在的合理性一样,鄙人偶尔会提出一些看似疯狂的质疑。 请问,性工作为什么遭到社会、法律、道德的歧视,她...
    心灵诊室阅读 280评论 0 0
  • 图文/幸福 对明代心学的探究,到李贽这时,我不知道为什么,有学术领域中的空白。哲学不是我主修的课程,文史只要求学生...
    有点个性阅读 592评论 0 0