虚拟机01:192.168.111.131
虚拟机02:192.168.111.128
虚拟机01用作 将镜像上传到私人仓库 虚拟机02用作 拉取镜像
二、搭建私有仓库
下载虚拟机01registry
[root@localhost ~]# docker pull registry Using default tag: latest latest: Pulling from library/registry 79e9f2f55bf5: Pull complete 0d96da54f60b: Pull complete 5b27040df4a2: Pull complete e2ead8259a04: Pull complete 3790aef225b9: Pull complete Digest: sha256:169211e20e2f2d5d115674681eb79d21a217b296b43374b8e39f97fcf866b375 Status: Downloaded newer image for registry:latest docker.io/library/registry:latest [root@localhost ~]#
2.创建仓库容器并运行
[root@localhost ~]# docker run -d -v /home/registory:/var/lib/registry -p 5000:5000 --restart=always --privileged=true --name registry registry:latest WARNING: IPv4 forwarding is disabled. Networking will not work. 1e9a65b8d6cbdeb12f0dccb0133d83ebf298bc9173f002c21bf0cb76065167f3 [root@localhost ~]#
3、修改daemon配置文件 /etc/docker/daemon.json (无自动创建)
注意同一{},不要忘记加号码
[root@localhost ~]# vi /etc/docker/daemon.json { "insecure-registries":["192.168.111.131:5000"], //注意我的ip换成自己的 "registry-mirrors": ["https://r1lazpp7.mirror.aliyuncs.com"] }
4、重启服务
[root@localhost ~]# systemctl daemon-reload [root@localhost ~]# systemctl restart docker
5、给nginx 打上 tag 标签
[root@localhost ~]# docker tag nginx:latest 192.168.111.131:5000/nginx:latest
6.上传到私人仓库
[root@localhost ~]# docker push 192.168.111.131:5000/nginx Using default tag: latest The push refers to repository [192.168.111.131:5000/nginx] b6812e8d56d6: Pushed 7046505147d7: Pushed c876aa251c80: Pushed f5ab86d69014: Pushed 4b7fffa0f0a4: Pushed 9c1b6dd6c1e6: Pushed latest: digest: sha256:61face6bf030edce7ef6d7dd66fe452298d6f5f7ce032afdd01683ef02b2b841 size: 1570 [root@localhost ~]#
检查仓库镜像 , 上传成功
[root@localhost ~]# curl http://192.168.111.131:5000/v2/_catalog {"repositories":["nginx"]} [root@localhost ~]#
三、虚拟机02 拉私人仓库镜像
1、同样修改daemon配置文件 /etc/docker/daemon.json (无自动创建)
[root@localhost ~]# vim /etc/docker/daemon.json { "insecure-registries":["192.168.111.131:5000"] }
2.同样重启服务
[root@localhost ~]# systemctl daemon-reload [root@localhost ~]# systemctl restart docker
同样拉取镜像
[root@localhost ~]# docker pull 192.168.111.131:5000/nginx Using default tag: latest latest: Pulling from nginx 1fe172e4850f: Pull complete 35c195f487df: Pull complete 213b9b16f495: Pull complete a8172d9e19b9: Pull complete f5eee2cb2150: Pull complete 93e404ba8667: Pull complete Digest: sha256:61face6bf030edce7ef6d7dd66fe452298d6f5f7ce032afdd01683ef02b2b841 Status: Downloaded newer image for 192.168.111.131:5000/nginx:latest 192.168.111.131:5000/nginx:latest [root@localhost ~]#
查看是否有 192.168.111.131:5000/nginx
[root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE 192.168.111.131:5000/nginx latest fa5269854a5e 9 days ago 142MB [root@localhost ~]#
拉取成功
四、创建多个库
[root@localhost ~]# vim /etc/docker/daemon.json { "insecure-registries":["192.168.111.131:5000","ip地址:port2","ip地址:port3"], "registry-mirrors": ["https://r1lazpp7.mirror.aliyuncs.com"] }