Docker環境搭建 - Docker安裝Maven私服Nexus3
阿新 • • 發佈:2019-01-12
Docker 安裝 Nexus3 及配置
環境
在 Centos7 的虛擬機器上進行安裝,虛擬機器 IP 為 192.168.247.129
安裝
拉取映象
docker pull sonatype/nexus3
檢視映象
docker images
執行容器
docker run -d --name nexus3 -p 8081:8081 -v /nexus-data:/nexus-data sonatype/nexus3
訪問 Nexus3 首頁 http://192.168.247.129:8081
,使用 admin / admin123 進行登入
Nexus 的倉庫分為這麼幾類:
- hosted 宿主倉庫:主要用於部署無法從公共倉庫獲取的構件(如 oracle 的 JDBC 驅動)以及自己或第三方的專案構件;
- proxy 代理倉庫:代理公共的遠端倉庫;
- virtual 虛擬倉庫:用於適配 Maven 1;
- group 倉庫組:Nexus 通過倉庫組的概念統一管理多個倉庫,這樣我們在專案中直接請求倉庫組即可請求到倉庫組管理的多個倉庫。
配置 Maven 使用 Nexus 私服
對 Maven 配置檔案 settings.xml 進行配置
配置私服映象
<mirrors> <mirror> <id>central</id> <mirrorOf>*</mirrorOf> <!-- * 表示讓所有倉庫使用該映象--> <name>central-mirror</name> <url>http://192.168.247.129:8081/repository/maven-public/</url> </mirror> </mirrors>
mirrorOf 表示代理的映象," * " 表示將 Nexus 配置成所有倉庫的映象,central 表示將 Nexus 配置成中央倉庫的映象
配置阿里雲倉庫代理中央倉庫,Nexus 代理其它倉庫
<mirror> <id>nexus-aliyun</id> <name>Nexus aliyun</name> <url>http://maven.aliyun.com/nexus/content/groups/public</url> <mirrorOf>central</mirrorOf> </mirror> <mirror> <id>nexus</id> <mirrorOf>*</mirrorOf> <url>http://192.168.247.129:8081/repository/maven-public/</url> </mirror>
配置 Nexus 作為快照倉庫
<profiles>
<profile>
<id>nexus-resp</id>
<repositories>
<repository>
<id>nexus-releases</id>
<url>http://192.168.247.129:8081/repository/maven-releases/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>false</enabled></snapshots>
</repository>
<repository>
<id>nexus-snapshots</id>
<url>http://192.168.247.129:8081/repository/maven-snapshots/</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus-plugin</id>
<url>http://192.168.247.129:8081/repository/maven-public/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>false</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus-resp</activeProfile>
</activeProfiles>
配置完成,本地 Maven 專案就可以從 Nexus 私服拉取專案依賴。
將本地專案打包至私服
配置上傳帳戶密碼(配置在Maven的配置檔案 settings.xml 中)
<server>
<id>nexus-releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
配置部署釋出版及快照版(配置在專案的 pom 檔案中)
<distributionManagement>
<repository>
<id>nexus-release</id>
<url>http://localhost:8081/repository/maven-public/</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<url>http://localhost:8081/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
配置完成,本地專案執行 deploy 時,就會上傳至 Nexus 私服。