使用Docker搭建Nexus私有仓库
一、docker安装nexus
官方镜像地址:https://hub.docker.com/r/sonatype/nexus3/tags
pull images
docker pull sonatype/nexus3
安装
#新建目录 mkdir /usr/local/docker/nexus #修改权限 chmod 777 /usr/local/docker/nexus #nexus默认使用8081端口 docker run -d --restart=always -p 8081:8081 --name nexus -v /usr/local/docker/nexus:/nexus-data sonatype/nexus3
默认密码
#进入容器 docker exec -it nexus /bin/bash #进入/opt/sonatype/sonatype-work/sonatype-work/目录,找到admin.password文件,里面的内容就是密码 cat admin.password # 此时的密码是临时密码需要自行修改 ## 二、配置nexus **admin** 权限登录 **nexus **管理平台后 #### 1、创建Blob stores 在创建repository之前,还需要先指定文件存储目录,便于统一管理。就需要创建Blob stores  创建好后可以看到blob stores有两个,一个是系统默认的,一个是刚创建的。如果不想自己创建,使用系统默认的文件存储目录(在sonatype-work/nexus3/blobs)也是可以的。到时候创建repository时,存储目录选择default就可以了。  #### 2、nexus仓库  如图所示,代理仓库负责代理远程中央仓库,托管仓库负责本地资源,组资源库 = 代理资源库 + 托管资源库。 #### 3、创建proxy repository代理仓库 
选择maven2(proxy),代理仓库
设置代理仓库
其他的可以采用默认,以后需要修改的可以再修改。
4.创建hosted repository仓库
上图的Hosted设置选项,选项中有三个值:
Allow redeploy:允许同一个版本号下重复提交代码, nexus以时间区分
Disable redeploy:不允许同一个版本号下重复提交代码
Read-Only:不允许提交任何版本
原生的maven-releases库是Disable redeploy设置, maven-snapshots是Allow redeploy。5、创建group repository组仓库
将hosted repositories宿主仓库的顺序放在proxy repositories代理仓库之前,因为一个group仓库组中可以包括宿主仓库和代理仓库。而整个group repository是作为一个public repository给用户使用的。
所以当查找jar包的时候,如果代理资源库在前面,那就是先从远程去查找jar包,而不是先从宿主仓库(本地仓库)去查找jar包。
三、设置maven
Maven下的setting.xml文件和项目中的pom.xml文件的关系是:settting.xml文件是全局设置,而pom.xml文件是局部设置。pom.xml文件对于项目来说,是优先使用的。而pom.xml文件中如果没有配置镜像地址的话,就按照settting.xml中定义的地址去查找。
1、修改maven配置文件setting.xml
如上图方式获取组仓库smart_group的仓库地址,修改setting.xml文件如下:
smart_group admin admin123 smart_group smart_group http://******:8081/repository/smart_group/ central 修改后可以重新编译项目,必须添加参数-U,(-U,--update-snapshots,强制更新releases、snapshots类型的插件或依赖库,否则maven一天只会更新一次snapshot依赖)。代理仓库会从远程中央仓库下载jar包


## 参考资料
1、https://blog.csdn.net/localhost01/article/details/84350773
2、https://blog.csdn.net/lupengfei1009/article/details/93202578
3、https://www.cnblogs.com/alan6/p/13038665.html
此处评论已关闭