Docker系列教程03-Docker私有仓库搭建(registry)

docker run -d -v /opt/registry:/var/lib/registry -p 5000:5000 --name myregistry registry:2



> 
> registry服务默认将上传的镜像保存在容器的`/var/lib/registry`,使用`-v`参数将容器的/var/lib/registry目录映射到本地/opt/registry目录。即可实现将镜像保存到宿主机/opt/registry目录。
> 
> 
> 


浏览器访问`http://宿主机IP:5000/v2`,显示“`{}`” 说明registry运行正常。


![](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9tbWJpei5xcGljLmNuL21tYml6X3BuZy9jYkNMZ2ZKWmlicHJpY250bVdXZXF6WWYwUkhNY0kwNEVlOTZvU29LUXBZNTA2WEVlTDViNnBPeXMzTkpNNXkzQzNVRE0yaHJOTlVqWVo3RWlhNk1nNVNWZy82NDA?x-oss-process=image/format,png)
### 上传镜像到私有仓库


现在通过push将镜像上传至私有仓库,具体步骤如下:



1、下载docker hub官方镜像
docker pull ubuntu

2、将镜像标志为要推送到私有仓库:
docker tag ubuntu:latest 10.43.187.251:5000/myubuntu:v1

3、上传镜像到私有仓库
[root@qll251 ~]# docker push 10.43.187.251:5000/myubuntu:v1
The push refers to repository [10.43.187.251:5000/myubuntu]
Get https://10.43.187.251:5000/v2/: http: server gave HTTP response to HTTPS client


注意,上传镜像时报错了:`http: server gave HTTP response to HTTPS client`



> 
> 出现这个问题原因是:**Docker自从1.3.X之后docker registry交互默认使用的是HTTPS,但是搭建私有镜像默认使用的是HTTP服务,所以与私有仓库交互时出现以上错误。**
> 
> 
> 


解决办法:


1、编辑 `/etc/docker/daemon.json`,在文件中写入:



{ “insecure-registries”:[“10.43.187.251:5000”] }


2、重启生效:



systemctl daemon-reload
systemctl restart docker


再次上传,问题解决:



docker pull 10.43.187.251:5000/myubuntu:v1


### 客户端下载私有镜像


我们在另外一台docker机器上,进行pull测试:



[root@qll252 ~]# docker pull 10.43.187.251:5000/myubuntu:v1
Trying to pull repository 10.43.187.251:5000/myubuntu …
Get https://10.43.187.251:5000/v1/_ping: http: server gave HTTP response to HTTPS client


会发现跟前面上传镜像报了同样的错误。


**解决方法同上:**


![](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9tbWJpei5xcGljLmNuL21tYml6X3BuZy9jYkNMZ2ZKWmlicHJpY250bVdXZXF6WWYwUkhNY0kwNEVlbzRpY2JwRElaRkxwU29FaWFCU05NWFdDWFlWQnJpY1F4TVhtcmpLbVVRallHRFVmWDZBUUJzTGJBLzY0MA?x-oss-process=image/format,png)
再次从私有仓库中下载镜像:



[root@qll252 ~]# docker pull 10.43.187.251:5000/myubuntu:v1
Trying to pull repository 10.43.187.251:5000/myubuntu …
v1: Pulling from 10.43.187.251:5000/myubuntu
d51af753c3d3: Pull complete
fc878cd0a91c: Pull complete
6154df8ff988: Pull complete
fee5db0ff82f: Pull complete
Digest: sha256:5747316366b8cc9e3021cd7286f42b2d6d81e3d743e2ab571f55bcd5df788cc8
Status: Downloaded newer image for 10.43.187.251:5000/myubuntu:v1


验证通过,到此已完成私有仓库的搭建工作了。



> 
> 说明:在后续教程我们学习到`docker-compose`时,再为大家介绍企业级Harbor私有仓库及搭建过程。
> 
> 
> 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值