使用Docker安裝nexus3,搭建maven私服
阿新 • • 發佈:2020-10-26
拉取nexus3映象
image.png檢視映象
docker images
image.png
執行nexus容器
docker run -id --privileged=true --name=nexus3 --restart=always -p 8081:8081 -v /kichun/nexus3/nexus-data:/var/nexus-data 6e9721ad473a(這個是容器id或名稱)
解釋:
-id 建立守護式容器
--privileged=true 授予root許可權(掛載多級目錄必須為true,否則容器訪問宿主機許可權不足)
--name=名字 給你的容器起個名字
-p 宿主機埠:容器埠對映
-v 宿主機目錄:容器目錄 目錄掛載
image.png
注意:
執行容器後訪問主機+配置的宿主機對映埠無反應時,請稍等幾分鐘(視配置時間長短不一),等待nexus3完成初始化才能訪問成功
訪問nexus3
image.png登入
預設admin密碼admin123
image.png
檢視倉庫
image.png在專案中配置私服
拷貝public倉庫地址
image.png
配置到你本地maven的settings檔案
注意:是public group倉庫地址而不是releases或snapshots倉庫,public預設包含了這兩個倉庫
<profiles>
<profile>
<id>dev</id>
<repositories>
<repository>
<id>local-nexus</id>
<url>http://192.168.3.128:8081/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>dev</activeProfile>
</activeProfiles>
image.png
配置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>
image.png
在專案父pom檔案中配置部署環境,注意id及URL必須與nexus倉庫對應
<!--私服倉庫-->
<distributionManagement>
<repository>
<id>maven-releases</id>
<name>Nexus Release Repository</name>
<url>http://192.168.3.128:8081/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>maven-snapshots</id>
<name>Nexus Snapshot Repository</name>
<url>http://192.168.3.128:8081/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
image.png
重新開啟專案,對需要的模組進行deploy
image.png
在nexus中檢視上傳的jar
image.png