三台机器:docker
192.168.20.201 搭建私有仓库bash
192.168.20.202 push镜像curl
192.168.20.203 pull镜像测试
2-1 下载registry镜像: url
使用 192.168.20.201 机器:spa
docker pull registry
2-2 启动registry镜像: rest
docker run -d -p 5000:5000 -v /tmp/registry:/tmp/registry registry:latest
默认状况下,仓库会将镜像存放于容器内的/tmp/registry目录下,若是容器被删除,则存放于容器中的镜像也会丢失,因此指定一个目录挂载到容器内的/tmp/registry下code
3-1 在192.168.20.202 随便准备一个镜像,搞个 helloworld 镜像io
3-2 修改该镜像标签class
docker tag docker.io/hello-world:latest 192.168.20.201:5000/hello-world:latest
重命名为:私有仓库所在机器IP + 端口号 + 镜像name + 镜像tag
3-3 push镜像
docker push 192.168.20.201:5000/hello-world:latest
会出现如下错误:
缘由:与docker registry交互时,默认使用的是https,而搭建的私有仓库只提供http服务
解决办法:修改三台机器的 /etc/sysconfig/docker 配置文件,添加
--insecure-registry 192.168.20.201:5000(仓库所在电脑地址)
或者是
exec "$DOCKER" -d $DOCKER_OPTS --insecure-registry 192.168.20.201:5000
3-4 重启三台机器的docker
systemctl restart docker.service
3-5 push镜像
在 192.168.20.202 执行
docker push 192.168.20.201:5000/hello-world:latest
3-6 pull镜像
在 192.168.20.203 执行
docker pull 192.168.20.203:5000/hello-world
成功从私有仓库获取到hello-world镜像
3-7 查看私有仓库镜像
在 192.168.20.201 执行:
查看全部镜像:
curl localhost:5000/v2/_catalog
查看具体镜像tag:
curl localhost:5000/v2/hello-world/tags/list