首先添加一个镜像加速
##注意分隔符
vim /etc/docker/daemon.json
"registry-mirrors": ["https://8auvmfwy.mirror.aliyuncs.com"]
1.拉取最新镜像
docker pull registry
2.将registry镜像运行并生成一个容器
docker run -d -v /opt/registry:/var/lib/registry -p 5000:5000 --restart=always --name registry registry:latest
-v 参数本地挂载到/opt/registry中
3.因为我们启动的registry服务不是安全可信赖的。这时需要修改客户端docker的配置文件/etc/docker/daemon.json
##集群中要用到私仓的都要修改
"registry-mirrors": [ "https://pee6w651.mirror.aliyuncs.com"],"insecure-registries": ["192.168.26.130:5000"]
https://pee6w651.mirror.aliyuncs.com 为国内镜像仓代理,
192.168.26.130:5000 为registry启动的机器ip
重启docker生效
systemctl restart docker
命令查看
curl -XGET http://192.168.26.130:5000/v2/_catalog
4.搭建完成,开始测试
[root@k8s-01 ~]# docker pull nginx ##集群任一节点拉取
Using default tag: latest
latest: Pulling from library/nginx
69692152171a: Pull complete
49f7d34d62c1: Pull complete
5f97dc5d71ab: Pull complete
cfcd0711b93a: Pull complete
be6172d7651b: Pull complete
de9813870342: Pull complete
Digest: sha256:df13abe416e37eb3db4722840dd479b00ba193ac6606e7902331dcea50f4f1f2
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
[root@k8s-01 ~]# docker images ##查看本地镜像
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest f0b8a9a54136 11 days ago 133MB
calico/node v3.19.0 b0744cc52c19 3 weeks ago 153MB
calico/pod2daemon-flexvol v3.19.0 a5decf77918d 3 weeks ago 21.7MB
calico/cni v3.19.0 3d17cd6307a4 3 weeks ago 146MB
calico/node v3.15.5 f0393ae546b5 4 weeks ago 437MB
calico/pod2daemon-flexvol v3.15.5 0cdfd80862a1 4 weeks ago 21.9MB
calico/cni v3.15.5 42b7a3f2bfdf 4 weeks ago 109MB
registry.aliyuncs.com/google_containers/kube-proxy v1.18.14 8e6bca1d4e68 5 months ago 117MB
registry.aliyuncs.com/google_containers/kube-apiserver v1.18.14 f17e261f4c8a 5 months ago 173MB
registry.aliyuncs.com/google_containers/kube-controller-manager v1.18.14 b734a959c6fb 5 months ago 162MB
registry.aliyuncs.com/google_containers/kube-scheduler v1.18.14 95660d582e82 5 months ago 95.3MB
registry.aliyuncs.com/google_containers/pause 3.2 80d28bedfe5d 15 months ago 683kB
registry.aliyuncs.com/google_containers/coredns 1.6.7 67da37a9a360 16 months ago 43.8MB
registry.aliyuncs.com/google_containers/etcd 3.4.3-0 303ce5db0e90 19 months ago 288MB
[root@k8s-01 ~]# docker tag nginx 192.168.26.130:5000/nginx-5-23 ##tag成标准格式
[root@k8s-01 ~]# docker push 192.168.26.130:5000/nginx-5-23 ##上传镜像
Using default tag: latest
The push refers to repository [192.168.26.130:5000/nginx-5-23]
f0f30197ccf9: Pushed
eeb14ff930d4: Pushed
c9732df61184: Pushed
4b8db2d7f35a: Pushed
431f409d4c5a: Pushed
02c055ef67f5: Pushed
[root@k8s-04 ~]# curl -XGET http://192.168.26.130:5000/v2/_catalog ##换个节点查看私仓状态
{"repositories":["nginx-5-23"]}
[root@k8s-04 ~]# docker pull 192.168.26.130:5000/nginx-5-23 ##拉取成功
Using default tag: latest
latest: Pulling from nginx-5-23
69692152171a: Pull complete
49f7d34d62c1: Pull complete
5f97dc5d71ab: Pull complete
cfcd0711b93a: Pull complete
be6172d7651b: Pull complete
de9813870342: Pull complete
Digest: sha256:eba373a0620f68ffdc3f217041ad25ef084475b8feb35b992574cd83698e9e3c
Status: Downloaded newer image for 192.168.26.130:5000/nginx-5-23:latest
192.168.26.130:5000/nginx-5-23:latest