环境准备 安装好 docker-ce
[root@localhost ~]# ./image.sh
运行 Registry
[root@localhost ~]# docker run -d -v /opt/registry:/var/lib/registry -p 5000:5000 --restart=always --name registry registry:latest
查看运行情况
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f7ea0b861276 registry:latest "/entrypoint.sh /etc…" 33 seconds ago Up 29 seconds 0.0.0.0:5000->5000/tcp registry
查看状态 在浏览器输入地址 http://ip_add:5000/v2/
上传镜像 #ip 为自己主机ip
[root@localhost ~]# vi /etc/docker/daemon.json
{
"insecure-registries":["192.168.220.10:5000"]
}
[root@localhost ~]# systemctl restart docker
使用 docker tag 命令将 centos:latest 这个镜像标记为 192.168.220.10:5000/centos:latest:
[root@localhost ~]# docker tag centos:latest 192.168.220.10:5000/centos:latest
使用 docker push 命令上传标记的镜像:
[root@localhost ~]# docker push 192.168.220.10:5000/centos:latest
The push refers to repository [192.168.220.10:5000/centos]
9e607bb861a7: Pushed
latest: digest: sha256:6ab380c5a5acf71c1b6660d645d2cd79cc8ce91b38e0352cbf9561e050427baf size: 529
使用 curl 命令查看仓库中的镜像:
[root@localhost ~]# curl -L http://192.168.220.10:5000/v2/_catalog
{"repositories":["centos"]}
在浏览器中可看到
拉取镜像——另一台从节点查看,环境一致安装docker
[root@slave ~]# vi /etc/docker/daemon.json
{
"insecure-registries":["192.168.220.10:5000"]
}
[root@slave ~]# systemctl restart docker
[root@slave ~]# docker pull 192.168.220.10:5000/centos:latest
latest: Pulling from centos
729ec3a6ada3: Pull complete
Digest: sha256:6ab380c5a5acf71c1b6660d645d2cd79cc8ce91b38e0352cbf9561e050427baf
Status: Downloaded newer image for 192.168.220.10:5000/centos:latest