1. 获取镜像
# 查看可用的稳定版本
sudo docker search nexus
sudo docker pull sonatype/nexus3
sudo docker image ls |grep nexus
2. 创建数据卷
sudo mkdir -p /home/nexus-data
# 赋予data目录读写权限
sudo chmod 777 /home/nexus-data
3. 启动容器
sudo docker run -d -p 8081:8081 --name nexus \
--restart=always \
-v /home/nexus-data:/var/nexus-data \
-e TZ=Asia/Shanghai \
sonatype/nexus3
sudo docker start nexus
sudo docker restart nexus
sudo docker stop nexus
sudo docker rm nexus
4. 配置
- Maven工程配置(pom.xml)
```xml
polarisrs http://10.0.37.221:18081/repository/xwhy-release/
- **Maven配置(setting.xml)**
```xml
<servers>
<server>
<id>polarisrs</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
5. 验证
sudo docker logs nexus
sudo docker exec -it nexus /bin/bash
# 查看密码(默认账户口令:admin/admin123)
# 在nexus3中,其密码已经由默认改成随机生成
cat /nexus-data/admin.password
# 打包发布命令
mvn deploy
WebUI:http://${domain}:8081