拉取nexus3鏡像
docker pull docker.io/sonatype/nexus3
查看鏡像
docker images

運行nexus容器
docker run -id --privileged=true --name=nexus3 --restart=always -p 8081:8081 -v /lpg/nexus3/nexus-data:/var/nexus-data 6e9721ad473a
6e9721ad473a(這個是鏡像id或名稱)
解釋:
-id 創建守護式容器
--privileged=true 授予root權限(掛載多級目錄必須為true,否則容器訪問宿主機權限不足)
--name=名字 給你的容器起個名字
-p 宿主機端口:容器端口映射
-v 宿主機目錄:容器目錄 目錄掛載
注意:
運行容器后訪問主機+配置的宿主機映射端口無反應時,請稍等幾分鍾(視配置時間長短不一),等待nexus3完成初始化才能訪問成功
通過查看日志可以看出是否啟動成功:

當看到如下日志,說明啟動成功

訪問nexus3
使用主機ip+啟動容器端口訪問:
登錄
默認用戶名為admin,密碼是一串字符串,首次登錄會提示在服務器的具體某個位置,可以通過進入容器的方式訪問密碼所在地,拿到密碼登錄並更改默認密碼。
訪問容器方式:
docker exec -it c96fe58560c2 /bin/bash
c96fe58560c2 :容器id
查看倉庫
在項目中配置私服
拷貝public倉庫地址
配置到你本地maven的settings文件
注意:是public group倉庫地址而不是releases或snapshots倉庫,public默認包含了這兩個倉庫
<profiles> <profile> <id>dev</id> <repositories> <repository> <id>local-nexus</id> <url>http://ip:8081/repository/maven-public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> </profile> </profiles> <activeProfiles> <activeProfile>dev</activeProfile> </activeProfiles>
配置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>
在項目父pom文件中配置部署環境,注意id及URL必須與nexus倉庫對應
<!--私服倉庫--> <distributionManagement> <repository> <id>maven-releases</id> <name>Nexus Release Repository</name> <url>http://ip:8081/repository/maven-releases/</url> </repository> <snapshotRepository> <id>maven-snapshots</id> <name>Nexus Snapshot Repository</name> <url>http://ip:8081/repository/maven-snapshots/</url> </snapshotRepository> </distributionManagement>
重新打開項目,對需要的模塊進行deploy
在nexus中查看上傳的jar

docker images
