Docker安装私有仓库Nexus

Nexus是一种特殊的远程仓库,它是架在局域网内的仓库服务。可以用于局域网中搭建docker、maven私有仓库。

创建挂载目录

1
2
#创建挂载目录
mkdir -p ./data/nexus/data && chmod 777 ./data/nexus/data

docker-compose.yml文件编写

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
version: '3.0'
services:
nexus:
restart: always
image: sonatype/nexus3
container_name: my_nexus
volumes:
- ./data/nexus/data:/nexus-data
ports:
- "8081:8081"
- "8082:8082"
- "8083:8083"
- "8084:8084"
environment:
- "INSTALL4J_ADD_VM_PARAMS=-Xms128m -Xmx512m -XX:MaxDirectMemorySize=512m -Djava.util.prefs.userRoot=/nexus-data/javaprefs"
- TZ=Asia/Shanghai

# 安装,需要2-3分钟
docker-compose up -d

浏览器访问 http://ip:8081/

登录docker容器查看密码

docker exec -it nexus3 cat /nexus-data/admin.password && echo

创建仓库

仓库有3种类型

- hosted类型:即我们自己的宿主仓库,专门存储我们自己的aar或jar,上传aar也是上传到这种仓库。

- proxy类型:即用来代理中央仓库的,中央仓库就是maven或google或jcenter或其它组织公开的仓库,创建这种仓库的时候,需要填写一个中央仓库的url即可。为什么要加proxy仓库呢,因为你的aar中可能依赖了maven central或jcenter或google的aar,它会去代理仓库中去找这些aar,找到后会下载到你的maven仓库中。

- group类型:仓库组,即我们自己对外的仓库。它是一个仓库组,我们可以将hosted类型和proxy类型的仓库按照指定顺序加到这个仓库组中。在Android Studio的root project的build.gradle中填写仓库地址就是这个。在依赖aar或jar的时候,就是在group仓库组中按照仓库顺序寻找aar。