Maven私服:Docker安装nexus3

心血来潮,想自己搭个项目试试,锻炼下架构相关的东东。其中的一步就是搭建maven私服,方便自己部署私包。

查找nexus3镜像

docker search nexus3
image.png

拉取nexus3镜像

docker pull docker.io/sonatype/nexus3
image.png

查看镜像

docker images
image.png

运行nexus容器

docker run -id --privileged=true --name=nexus3 --restart=always -p 8081:8081 -v /kichun/nexus3/nexus-data:/var/nexus-data 6e9721ad473a(这个是容器id或名称)

解释:
-id 创建守护式容器
--privileged=true 授予root权限(挂载多级目录必须为true,否则容器访问宿主机权限不足)
--name=名字 给你的容器起个名字
-p 宿主机端口:容器端口映射
-v 宿主机目录:容器目录 目录挂载


image.png

注意:
运行容器后访问主机+配置的宿主机映射端口无反应时,请稍等几分钟(视配置时间长短不一),等待nexus3完成初始化才能访问成功

访问nexus3

image.png

登录

默认admin密码admin123


image.png

查看仓库

image.png

在项目中配置私服

拷贝public仓库地址


image.png

配置到你本地maven的settings文件
注意:是public group仓库地址而不是releases或snapshots仓库,public默认包含了这两个仓库

 <profiles>
    <profile>  
    <id>dev</id>  
    <repositories>  
     <repository>  
        <id>local-nexus</id>
        <url>http://192.168.3.128:8081/repository/maven-public/</url>  
        <releases>  
          <enabled>true</enabled>
        </releases>  
        <snapshots>  
          <enabled>true</enabled>  
        </snapshots>  
      </repository> 
    </repositories>  
  </profile>  
  </profiles>

  <activeProfiles>  
      <activeProfile>dev</activeProfile>  
    </activeProfiles>
image.png

配置maven settings文件的服务器用户名密码
注意:id为私服中releases和snapshots仓库名,必须一致

  <!-- servers
   | This is a list of authentication profiles, keyed by the server-id used within the system.
   | Authentication profiles can be used whenever maven must make a connection to a remote server.
   |-->
  <servers>
    <server>  
        <id>maven-releases</id>  
        <username>admin</username>  
        <password>admin123</password>  
      </server>  
      <server>  
        <id>maven-snapshots</id>  
        <username>admin</username>  
        <password>admin123</password>  
      </server> 
  </servers>
image.png

在项目父pom文件中配置部署环境,注意id及URL必须与nexus仓库对应

    <!--私服仓库-->
    <distributionManagement>
        <repository>
            <id>maven-releases</id>
            <name>Nexus Release Repository</name>
            <url>http://192.168.3.128:8081/repository/maven-releases/</url>
        </repository>
        <snapshotRepository>
            <id>maven-snapshots</id>
            <name>Nexus Snapshot Repository</name>
            <url>http://192.168.3.128:8081/repository/maven-snapshots/</url>
        </snapshotRepository>
    </distributionManagement>
image.png

重新打开项目,对需要的模块进行deploy


image.png

在nexus中查看上传的jar


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

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,001评论 19 139
  • 首先私服是一种衍生出来的特殊的Maven远程仓库,构建私服的好处请看3.5私服 可以帮助大家建立私服的仓库管理软件...
    zlcook阅读 10,668评论 0 32
  • |-1-更新内容[6.从仓库解析依赖的机制(重要)] 1Maven仓库作用 仓库用来存储所有项目使用到构件,在ma...
    zlcook阅读 6,178评论 0 25
  • 每当我做错事情的时候,我总是拿自己还是个孩子为借口逃避心里的愧疚,无可置疑,我是长辈眼中永远长不大的孩子,而这也成...
    漫舞洛城阅读 118评论 0 0
  • #Socket简介 是一个编程接口 是一种特殊的文件描述符(everything in Unix is a fil...
    我替上帝收尸阅读 1,996评论 0 1