拉取nexus3镜像
docker pull docker.io/sonatype/nexus3
查看镜像
docker images

运行nexus容器
docker run -id --privileged=true --name=nexus3 --restart=always -p 8081:8081 -v /lpg/nexus3/nexus-data:/var/nexus-data 6e9721ad473a
6e9721ad473a(这个是镜像id或名称)
解释:
-id 创建守护式容器
--privileged=true 授予root权限(挂载多级目录必须为true,否则容器访问宿主机权限不足)
--name=名字 给你的容器起个名字
-p 宿主机端口:容器端口映射
-v 宿主机目录:容器目录 目录挂载
注意:
运行容器后访问主机+配置的宿主机映射端口无反应时,请稍等几分钟(视配置时间长短不一),等待nexus3完成初始化才能访问成功
通过查看日志可以看出是否启动成功:

当看到如下日志,说明启动成功

访问nexus3
使用主机ip+启动容器端口访问:
登录
默认用户名为admin,密码是一串字符串,首次登录会提示在服务器的具体某个位置,可以通过进入容器的方式访问密码所在地,拿到密码登录并更改默认密码。
访问容器方式:
docker exec -it c96fe58560c2 /bin/bash
c96fe58560c2 :容器id
查看仓库
在项目中配置私服
拷贝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 images
