Docker部署Nexus

本文最后更新于 2024年12月2日 晚上

准备存储卷

1
mkdir ./data

创建docker-compose.yml

创建文件: /usr/local/nexus/docker-compose.yml, 内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
文件内容:
```yml
version: '3.1'
services:
nexus:
restart: always
image: sonatype/nexus3
container_name: nexus
ports:
- 8080:8080
volumes:
- ./data:/nexus-data

赋予权限

1
chmod 777 /usr/local/nexus/data

启动服务

1
docker-compose up -d

代理第三方仓库

登录nexus

用户名、密码: admin/admin

代理第三方仓库

创建proxy类型仓库:

1
2
3
4
5
http://mirrors.163.com/maven/repository/maven-public/
https://maven.aliyun.com/repository/public/
https://repo1.maven.org/maven2/
https://repo.spring.io/milestone/
https://repo.spring.io/snapshot/

代理仓库添加到public仓库

Maven settings.xml servers中添加认证信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<server>
<id>nexus-public</id>
<username>admin</username>
<password>admin</password>
</server>
<server>
<id>nexus-releases</id>
<username>admin</username>
<password>admin</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>admin</username>
<password>admin</password>
</server>

Maven settings.xml mirrors中配置只调用私服

1
2
3
4
5
6
<mirror>
<id>nexus-public</id>
<mirrorOf>*</mirrorOf>
<name>nexus-public</name>
<url>http://192.168.0.112:8081/repository/maven-public/</url>
</mirror>

Maven settings.xml profiles中配置连接信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<profile>
<id>nexus</id>
<repositories>
<repository>
<!--仓库id,repositories可以配置多个仓库,保证id不重复-->
<id>nexus-public</id>
<name>Nexus Repository</name>
<!--仓库地址,即nexus仓库组的地址-->
<url>http://192.168.0.112:8081/repository/maven-public/</url>
<!--是否下载releases构件-->
<releases>
<enabled>true</enabled>
</releases>
<!--是否下载snapshots构件-->
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<!-- 插件仓库,maven的运行依赖插件,也需要从私服下载插件 -->
<pluginRepository>
<!-- 插件仓库的id不允许重复,如果重复后边配置会覆盖前边 -->
<id>nexus-public</id>
<name>Nexus Plugin Repository</name>
<url>http://192.168.0.112:8081/repository/maven-public/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</pluginRepository>
</pluginRepositories>
</profile>

Maven settings.xml activeProfiles中启用配置

1
<activeProfile>nexus</activeProfile>

项目pom.xml中配置私服地址

1
2
3
4
5
6
7
8
9
10
11
12
<distributionManagement>  
<repository>
<id>nexus-releases</id>
<name>Nexus Release Repository</name>
<url>http://127.0.0.1:8081/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<name>Nexus Snapshot Repository</name>
<url>http://127.0.0.1:8081/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>

发布到仓库

1
mvn deploy

上传第三方jar

1
2
3
4
5
6
7
8
mvn deploy:deploy-file 
-DgroupId=com.aliyun.oss
-DartifactId=aliyun-sdk-oss
-Dversion=2.2.3
-Dpackaging=jar
-Dfile=D:\aliyun-sdk-oss-2.2.3.jar
-Durl=http://127.0.0.1:8081/repository/maven-3rd/
-DrepositoryId=nexus-releases

Docker部署Nexus
https://www.bugfree.top/2021/11/30/docker/Docker部署Nexus/
作者
lizhenguo
发布于
2021年11月30日
更新于
2024年12月2日
许可协议