使用Docker安装nexus3,搭建maven私服
拉取nexus3镜像
[root@server-04 ~]# docker pull docker.io/sonatype/nexus3
查看镜像
[root@server-04 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE sonatype/nexus3 latest 8c3731492925 10 days ago 629MB
运行nexus容器
[root@server-04 ~]# docker run -id --privileged=true --name=nexus3 --restart=always -p 8081:8081 -v /lpg/nexus3/nexus-data:/var/nexus-data 8c3731492925
解释:
-id 创建守护式容器
--privileged=true 授予root权限(挂载多级目录必须为true,否则容器访问宿主机权限不足)
--name=名字 给你的容器起个名字
-p 宿主机端口:容器端口映射
-v 宿主机目录:容器目录 目录挂载
注意:
运行容器后访问主机+配置的宿主机映射端口无反应时,请稍等几分钟(视配置时间长短不一),等待nexus3完成初始化才能访问成功
通过查看日志可以看出是否启动成功:
[root@server-04 ~]# docker logs nexus3
访问nexus3
使用主机ip+启动容器端口访问:
登录
默认用户名为admin,密码是一串字符串,首次登录会提示在服务器的具体某个位置,可以通过进入容器的方式访问密码所在地,拿到密码登录并更改默认密码。
访问容器方式:
[root@server-04 ~]# docker exec -it nexus3 /bin/bash bash-4.4$ cat /nexus-data/admin.password 79f3c39f-b707-4425-83a3-ef73632dee45
bash-4.4$
查看仓库
在项目中配置私服
拷贝public仓库地址
配置到你本地maven的settings文件
注意:是public group仓库地址而不是releases或snapshots仓库,public默认包含了这两个仓库
<profiles>
<profile>
<id>dev</id>
<repositories>
<repository>
<id>local-nexus</id>
<url>http://ip:8081/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>dev</activeProfile>
</activeProfiles>
配置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>
在项目父pom文件中配置部署环境,注意id及URL必须与nexus仓库对应
<!--私服仓库-->
<distributionManagement>
<repository>
<id>maven-releases</id>
<name>Nexus Release Repository</name>
<url>http://ip:8081/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>maven-snapshots</id>
<name>Nexus Snapshot Repository</name>
<url>http://ip:8081/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
重新打开项目,对需要的模块进行deploy
在nexus中查看上传的jar
分类:
docker进阶与实战
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?