注意点: 如果仓库的功能是拉取镜像,那么允许匿名;如果是上传镜像,那么不允许匿名。
1. 创建proxy仓库
- 设置名称
- 可以匿名访问,不打勾
- 支持API V1
- 配置远程仓库
- 选择存储blob,如没有,新建一个
2. 创建hosted仓库
- 设置名称
- 设置端口及不允许匿名访问
- 支持API V1,与proxy同
- 选择存储blob,与proxy同
- 上传策略
3. 创建group仓库
- 设置名称,端口
- 可以匿名、不打勾,与proxy同
- 支持API V1,与proxy同
- 选择存储blob,与proxy同
4. 客户端
- 配置
# registry-mirrors 配置docker加速器
# insecure-registries 配置私有镜像
[root@t40 ~]# cat /etc/docker/daemon.json
{"registry-mirrors":["http://r123m:8004"],"insecure-registries":["r123m:8003"]}
- 重启docker
[root@t40 ~]# systemctl daemon-reload
[root@t40 ~]# systemctl restart docker.service
5. 测试拉取镜像
- 测试拉取镜像,在拉取的过程中,不仅将镜像拉取到本地,也将在nexus中存储一份
[root@t40 ~]# docker image pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
Digest: sha256:90659bf80b44ce6be8234e6ff90a1ac34acbeb826903b02cfa0da11c82cbc042
Status: Downloaded newer image for hello-world:latest
docker.io/library/hello-world:latest
- 检查nexus是否有该镜像
6. 测试上传镜像
- 登录docker-third(hosted类型)
[root@t40 ~]# docker login r123m:8003
Username: admin
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
- 上传镜像
# 制作要上传的镜像
# 给要上传的镜像打标签,必须是 <hostname>:<port>/<repository>:<tag>形式
[root@t40 ~]# docker image tag hello-world:latest r123m:8003/hello-richard123m:latest
# 查看要上传的镜像
[root@t40 ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
r123m:8003/hello-richard123m latest bf756fb1ae65 3 months ago 13.3kB
hello-world latest bf756fb1ae65 3 months ago 13.3kB
# 推送镜像
[root@t40 ~]# docker image push r123m:8003/hello-richard123m:latest
The push refers to repository [r123m:8003/hello-richard123m]
9c27e219663c: Pushed
latest: digest: sha256:90659bf80b44ce6be8234e6ff90a1ac34acbeb826903b02cfa0da11c82cbc042 size: 525
- 检查docker-third(hosted类型)上是否有该镜像
- 测试拉取这个镜像,先检查本机是否有该镜像,如有,请删除。
[root@t40 ~]# docker pull r123m:8003/hello-richard123m:latest
latest: Pulling from hello-richard123m
Digest: sha256:90659bf80b44ce6be8234e6ff90a1ac34acbeb826903b02cfa0da11c82cbc042
Status: Downloaded newer image for r123m:8003/hello-richard123m:latest
r123m:8003/hello-richard123m:latest