准备两台装有docker的虚拟机
虚拟机01:192.168.111.131
虚拟机02:192.168.111.128
虚拟机01用作 上传镜像到私有仓库 虚拟机02用作 拉取镜像
[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 ~]#
[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 ~]#
要注意要在同一{}内,不要忘记加,号
[root@localhost ~]# vi /etc/docker/daemon.json
{
"insecure-registries":["192.168.111.131:5000"], //注意把我的ip换成你自己的
"registry-mirrors": ["https://r1lazpp7.mirror.aliyuncs.com"]
}
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl restart docker
[root@localhost ~]# docker tag nginx:latest 192.168.111.131:5000/nginx:latest
[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 ~]#
[root@localhost ~]# vim /etc/docker/daemon.json
{
"insecure-registries":["192.168.111.131:5000"]
}
[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"]
}