相關資料:
Sonatype Nexus3官方網站:https://www.sonatype.com/download-oss-sonatype
Sonatype Nexus3 Docker Hub地址:https://hub.docker.com/r/sonatype/nexus3/
Sonatype Nexus3一些介紹及使用:https://yeasy.gitbooks.io/docker_practice/repository/nexus3_registry.html
本文參考文章:https://www.cnblogs.com/holdengong/archive/2019/09/05/11468290.html,https://blog.csdn.net/supertor/article/details/83146596
⒈安裝Docker(必要條件)
請參考https://www.cnblogs.com/fanqisoft/p/10439620.html安裝Docker
⒉安裝Nexus3倉儲
1.拉取sonatype/nexus3鏡像
docker pull sonatype/nexus3
2.啟動容器
docker run -d --name nexus3 --restart=always -p 5000:5000 -p 8081:8081 --mount src=nexus-data,target=/nexus-data sonatype/nexus3
**5000端口是用於鏡像倉庫的服務端口 8081 端口是nexus的服務端口
3.訪問管理頁面
http://localhost:8081
4.登錄
//在docker目錄下查找admin.password文件並查看 cat `find /var/lib/docker -name admin.password -print` //這一串guid就是默認密碼 d374c028-9760-4dd8-b911-3cb67ebddba5
5.創建倉儲
點擊齒輪 - Repositories - Create repository - 選擇 docker (hosted)
Name: 倉庫的名稱
HTTP: 倉庫單獨的訪問端口
Enable Docker V1 API: 如果需要同時支持 V1 版本請勾選此項(不建議勾選)。
Hosted -> Deployment pollcy: 請選擇 Allow redeploy 否則無法上傳 Docker 鏡像。
其它的倉庫創建方法請各位自己摸索,還可以創建一個 docker (proxy) 類型的倉庫鏈接到 DockerHub 上。再創建一個 docker (group) 類型的倉庫把剛才的 hosted 與 proxy 添加在一起。主機在訪問的時候默認下載私有倉庫中的鏡像,如果沒有將鏈接到 DockerHub 中下載並緩存到 Nexus 中。
編寫信息完成后選擇“Create repository”按鈕
6.安全設置
官方介紹:https://help.sonatype.com/repomanager3/formats/docker-registry/authentication
點擊Realms菜單 - 把 Docker Bearer Token Realm 移到右邊的框中點擊Save保存。
添加用戶規則:菜單 Security->Roles->Create role 在 Privlleges 選項搜索 docker 把相應的規則移動到右邊的框中然后保存。
添加用戶:菜單 Security->Users->Create local user 在 Roles 選項中選中剛才創建的規則移動到右邊的窗口保存。
7.訪問倉儲(二選一)
1.Nginx加密代理,使用SSL訪問(需要生成證書),略。
2.配置Docker http可信地址
//編輯docker服務端設置 vim /etc/docker/daemon.json //將下面內容加到配置文件中 "insecure-registries":["http://localhost:5000"] //重載配置文件 systemctl daemon-reload //重啟Docker systemctl restart docker //查看設置是否生效 docker info
8.登錄nexus私有倉庫,測試是否可以連接成功
//輸入admin賬號密碼 docker login http://localhost:5000
**登錄后用戶信息保存在$HOME/.docker/config.json,如果需要切換賬號就清空該文件內容即可。
9.測試
1.制作image
//拉取hello-world鏡像作為示例 docker pull hello-world //制作私有鏡像 docker tag hello-world localhost:5000/hello-world
2.推送到私有倉庫
//推送到私有服務器 docker push localhost:5000/hello-world
10.查看
nexus還可以管理nuget,maven和其他包,可以作為企業集中資源管理中心。