1、安裝Nexus
docker run -d --name nexus3 --restart=always \
-p 8081:8081 \
-p 5000:5000 \
--mount src=nexus-data,target=/nexus-data \
sonatype/nexus3
注:8081端口是開放給後臺使用的,5000端口是開放給倉庫使用的,換成別的端口也可以,只要配置docker倉庫時填寫開放的端口就可以了
看到如下,說明安裝成功:
Unable to find image 'sonatype/nexus3:latest' locally
latest: Pulling from sonatype/nexus3
c65691897a4d: Pull complete
641d7cc5cbc4: Pull complete
c508b13320cd: Pull complete
79e3bf9d3132: Pull complete
Digest: sha256:2c33632ccd8f8c5f9023a3d7f5f541e271833e402219f8c5a83a29d1721457ca
Status: Downloaded newer image for sonatype/nexus3:latest
8b2d1ab8e59710d1aaf78c84ce2defca21b837092943266f5a55f1106b875fc6
2、查看密碼
docker exec nexus3 cat /nexus-data/admin.password
看到如下,記錄此密碼,待會登錄後臺需要:
f6dd0215-0445-46a1-8e90-e062dd04b3e0
3、登錄後臺
地址是IP:8081
例如我的是:
http://192.168.159.129:8081
看到如下界面:
4、點擊右上角sign in
賬號是admin
,密碼是剛纔查看的一串字符f6dd0215-0445-46a1-8e90-e062dd04b3e0
登錄成功後會提示你修改密碼,點next
去修改密碼即可
5、點擊上方設置按鈕進入管理界面
6、創建一個docker倉庫
選擇
新建倉庫,這裏不使用https
7、創建一個docker 角色
8、創建一個docker用戶
注:記住上面的id和密碼,待會命令行登錄需要用到
9、配置 Realms,把 Docker Realm 激活
10、打開/etc/docker/daemon.json文件,增加
"insecure-registries": [
"192.168.159.129:5000"
]
完整如下:
{
"registry-mirrors": [
"https://dockerhub.azk8s.cn",
"https://reg-mirror.qiniu.com"
],
"insecure-registries": [
"192.168.159.129:5000"
]
}
11、重新載入配置和重啓docker
systemctl daemon-reload
systemctl restart docker
12、現在命令行登錄docker
docker login 192.168.159.129:5000
輸入username和password
看到如下,表示登陸成功
Username: docker
Password:
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
13、查看現有鏡像
docker image ls
看到
REPOSITORY TAG IMAGE ID CREATED SIZE
sonatype/nexus3 latest 8eb898be2a53 4 weeks ago 611MB
hello-world latest fce289e99eb9 10 months ago 1.84kB
14、將hello-world重新打標籤push到倉庫
docker tag hello-world:latest 192.168.159.129:5000/hello-world:latest
docker push 192.168.159.129:5000/hello-world:latest
看到如下,表示成功
The push refers to repository [192.168.159.129:5000/hello-world]
af0b15c8625b: Pushed
latest: digest: sha256:92c7f9c92844bbbb5d0a101b22f7c2a7949e40f8ea90c8b3bc396879d95e899a size: 524
去後臺也可以看到push成功