Nexus3能夠支持Maven、Docker、NuGet、npm、Bower等,做爲一個穩定的私服產品經常用於咱們開發管理過程當中。java
用Nexus搭建本地私服有以下好處:docker
這些優勢使得Nexus日益成爲主流的倉庫管理器之一npm
閒話少敘,上圖json
Nexus3.x 相較 2.x 版本有很大的改變centos
1.下載Nexus3的鏡像瀏覽器
訪問hub.docker.com/,搜索nexus以下圖bash
選擇第一個,官方原裝進口版本,執行以下命令,我這裏已經下載好了服務器
root@surging:~# docker pull sonatype/nexus3
Using default tag: latest
latest: Pulling from sonatype/nexus3
Digest: sha256:3262783b5f44c6265cf867b390e84a643b855873b2018c0d28037d7cd29a89cf
Status: Image is up to date for sonatype/nexus3:latest
docker.io/sonatype/nexus3:latest
複製代碼
2.使用鏡像啓動一個容器less
$ docker run -d -p 8081:8081 -p 8082:8082 -p 8083:8083 --name nexus3 -v /home/nexus/nexus-data:/nexus-data --restart=always sonatype/nexus3複製代碼
注意 --restart=always:
加上這個指令無論退出狀態碼是什麼始終重啓容器。當指定always時,docker daemon將無限次數地重啓容器。容器也會在daemon啓動時嘗試重啓,無論容器當時的狀態如何。elasticsearch
啓動以後咱們就能夠經過http://服務器IP:8081訪問,相關界面以下圖
nexus3默認的帳號依舊是admin可是密碼已經變了具體的密碼存儲在nexus3的容器的nexus-data路徑內的admin.password文件內
具體操做:
a. 查看nexus3容器id,執行 docker ps
控制檯顯示
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2bc9db68ba83 elasticsearch:5.6.16 "/docker-entrypoint.…" 2 weeks ago Up 2 weeks 0.0.0.0:19200->9200/tcp, 0.0.0.0:19300->9300/tcp es5
01b398d530aa sonatype/nexus3 "sh -c ${SONATYPE_DI…" 2 weeks ago Up 2 weeks 0.0.0.0:8081-8083->8081-8083/tcp nexus3
e3a1b31ed4f4 registry:2 "/entrypoint.sh /etc…" 5 months ago Up 2 weeks 0.0.0.0:5000->5000/tcp registryb複製代碼
b. 進入容器控制檯執行 docker exec -it 01b398d530aa bash
控制檯顯示
docker exec -it 01b398d530aa bash
bash-4.4$ ls
bin boot dev etc help.1 home lib lib64 licenses lost+found media mnt nexus-data opt proc root run sbin srv sys tmp uid_entrypoint.sh uid_template.sh usr var
bash-4.4$ cd nexus-data/
bash-4.4$ ls
admin.password db generated-bundles karaf.pid log restore-from-backup
blobs elasticsearch instances keystores orient tmp
cache etc javaprefs lock portad複製代碼
admin.password中的第一行就是密碼,複製密碼使用admin登陸,登陸成功以後系統會自動提示你更換admin密碼
http://服務器IP:8081
點擊右上角進行登陸,密碼就是你剛纔設置的密碼:
點擊設置界面,選擇Repositories,點擊Create repository,以下圖所示:
這裏Docker有三種類型,分別是group、hosted、proxy。選擇docker(hosted),以下圖:
注:Docker鏡像倉庫類型含義解釋以下:
指定docker倉庫的名稱、指定一個端口用來經過http的方式進行訪問倉庫、勾選是否支持docker API V1,而後create repository;
我本地已經登陸過倉庫了,直接顯示成功,賬號密碼可使用admin,也能夠在nexus中自行配置,這裏就不贅述了
docker login 10.10.1.10:8082
Authenticating with existing credentials...
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded複製代碼