1.nexus官方网站:
首页
下载页
docker下载地址:https://hub.docker.com/r/sonatype/nexus3/
2.准备好docker环境
3.下载docker镜像
docker pull sonatype/nexus3:3.25.0
4.创建容器映射目录
mkdir -p /data/nexus3/nexus-data
chown -R 200 /data/nexus3/nexus-data (意思是,给这目录分配了UID为200的用户,nexus3会使用UID为200的用户操作该目录,否者会报错)
5 启动容器
docker run -d -p 8081:8081 --name nexus -v /app/nexus3/nexus-data:/nexus-data sonatype/nexus3:3.18.1
6 查看nexus3是否启动成功了
curl http://localhost:8081
7 查看容器日志
docker logs -f containerId
8.浏览器登陆http://(你的ip地址):8081
9.进入容器查看首次登陆密码
docker exec -it nexus /bin/bash
cat /opt/sonatype/sonatype-work/nexus3/admin.password
(如果cat不到,则说明已经登陆过了,登陆过后会删除admin.password文件)
10.点击signin登陆,登陆名为admin,密码为上面复制的密码,登陆后设置自己的密码
11.为Nexus配置阿里云代理仓库
可直接参考该博主,已经写得很详细了:为Nexus配置阿里云代理仓库
12.springboot工程中发布与引用
pom配置
<repositories>
<!--其它代码从阿里云下载-->
<repository>
<id>public</id>
<name>aliyun nexus</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<!--这里只引用snapshot版本-->
<repository>
<id>snapshots</id>
<name>myself-snapshot</name>
<url>http://127.0.0.1:8081/repository/myself-snapshot/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<!-- 使用分发管理将本项目打成jar包,直接上传到指定服务器 ,执行deployed命令时将jar包上传到配置仓库,要发布到私仓的必须为jar-->
<distributionManagement>
<!--用于存放后缀为snapshot版的仓库,建仓时指定仓库类型-->
<snapshotRepository>
<id>snapshots</id>
<name>nexus snapshot</name>
<url>http://127.0.0.1:8081/repository/myself-snapshot/</url>
</snapshotRepository>
<!--用于存放后缀为release版的仓库,建仓时指定仓库类型-->
<repository>
<id>nexus</id>
<name>nexus release</name>
<url>http://127.0.0.1:8081/repository/myself/</url>
</repository>
</distributionManagement>
13.注意事项,标签要跟maven的setting文件对应,没有就建下,url会覆盖setting中的url配置
14.如果项目中只是想指定私服地址,则可只要如下配置,不需要单独配置snapshot地址,public中一般会包含snapshot和release了
settings中的配置:
<server>
<id>lyrreoi</id>
<username>lyr</username>
<password>lyr</password>
</server>
<repositories>
<repository>
<id>lyrrepo</id> <!--该id要和maven中settings.xml的server相对应-->
<name>central</name>
<url>http://127.0.0.1:8181/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>hqrepo</id>
<name>central</name>
<url>http://127.0.0.1:8181/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
参考博客:进入容器与修改端口号
参考博客:https://www.cnblogs.com/moris5013/p/11440784.html