心血來潮,想自己搭個(gè)項(xiàng)目試試,鍛煉下架構(gòu)相關(guān)的東東。其中的一步就是搭建maven私服虱颗,方便自己部署私包。
查找nexus3鏡像
docker search nexus3
image.png
拉取nexus3鏡像
docker pull docker.io/sonatype/nexus3
image.png
查看鏡像
docker images
image.png
運(yùn)行nexus容器
docker run -id --privileged=true --name=nexus3 --restart=always -p 8081:8081 -v /kichun/nexus3/nexus-data:/var/nexus-data 6e9721ad473a(這個(gè)是容器id或名稱)
解釋:
-id 創(chuàng)建守護(hù)式容器
--privileged=true 授予root權(quán)限(掛載多級目錄必須為true蔗喂,否則容器訪問宿主機(jī)權(quán)限不足)
--name=名字 給你的容器起個(gè)名字
-p 宿主機(jī)端口:容器端口映射
-v 宿主機(jī)目錄:容器目錄 目錄掛載
image.png
注意:
運(yùn)行容器后訪問主機(jī)+配置的宿主機(jī)映射端口無反應(yīng)時(shí)忘渔,請稍等幾分鐘(視配置時(shí)間長短不一),等待nexus3完成初始化才能訪問成功
訪問nexus3
image.png
登錄
默認(rèn)admin密碼admin123
image.png
查看倉庫
image.png
在項(xiàng)目中配置私服
拷貝public倉庫地址
image.png
配置到你本地maven的settings文件
注意:是public group倉庫地址而不是releases或snapshots倉庫缰儿,public默認(rèn)包含了這兩個(gè)倉庫
<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文件的服務(wù)器用戶名密碼
注意: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
在項(xiàng)目父pom文件中配置部署環(huán)境,注意id及URL必須與nexus倉庫對應(yīng)
<!--私服倉庫-->
<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
重新打開項(xiàng)目乖阵,對需要的模塊進(jìn)行deploy
image.png
在nexus中查看上傳的jar
image.png