版权声明:本文由田飞雨原创文章,转载请注明出处:
文章原文连接:https://www.qcloud.com/community/article/94html
来源:腾云阁 https://www.qcloud.com/communitypython
去中央仓库下载镜像有时候很是的慢,因此 docker 本地仓库和 gitlab 相似,都是为了便于公司内部人员的使用。git
本次实验环境:腾讯云服务器 CentOS 6.7 x86_64github
# yum install -y python-devel libevent-devel python-pip gcc xz-devel
# pip install docker-registry
docker
也能够从 docker-registry 项目下载源码进行安装。shell
# docker run -d -p 5000:5000 registry #将使用官方的 registry 镜像来启动本地的私有仓库,可是并无启动,只是为你建立好
vim
默认状况下,会将仓库存放于容器的 /tmp/registry 目录下,若是容器被删除,则数据也会丢失,因此咱们能够经过 -v 参数来将镜像文件存放在本地的指定路径:服务器
# docker run -d -p 5000:5000 -v /opt/data/registry:/tmp/registry registry
# docker start $(docker ps -l | grep registry | awk '{print $1}') #启动仓库
要在本地仓库上传镜像,首先须要标记一个镜像,如下标记 busybox ,因为 busybox 镜像比较小,没有的建议先下载:curl
# docker pull buxybox # docker tag busybox 192.168.0.232:5000/busybox # 对 buxybox 镜像进行标记 # docker images #查看标记的镜像 # docker push 192.168.0.232:5000/busybox #而后开始上传吧 2016/06/14 11:01:17 Error: Invalid registry endpoint https://192.168.0.232:5000/v1/: Get https://192.168.0.232:5000/v1/_ping: dial tcp 192.168.0.232:5000: connection refused. If this private registry supports only HTTP or HTTPS with an unknown CA certificate, please add `--insecure-registry 192.168.0.232:5000` to the daemon's arguments. In the case of HTTPS, if you have access to the registry's CA certificate, no need for the flag; simply place the CA certificate at /etc/docker/certs.d/192.168.0.232:5000/ca.crt
呵呵,报错了!由于Docker从1.3.X以后默认docker registry使用的是https,因此当用docker pull命令下载远程镜像时,若是远程docker registry是非https的时候就会报上面的错误。tcp
为了解决这个问题须要在启动docker server时增长启动参数:
# vim /etc/sysconfig/docker #ip 换为本身的ip other_args="--insecure-registry 192.168.0.232:5000" #默认为空的 # service docker restart #重启docker # docker start $(docker ps -l | grep registry | awk '{print $1}') #启动 registry # docker push 192.168.0.232:5000/busybox #而后从新上传吧,此次确定成功 # curl http://192.168.0.232:5000/v1/search #查看上传的镜像 {"num_results": 1, "query": "", "results": [{"description": "", "name": "library/busybox"}]}
注意: /v1 表明 registry 的版本,使用 docker pull 安装的默认为 v1 版本。
测试:
使用另外一台机器 pull 本地的私有仓库,可是要在 private registry 上使用 SSL,另外一种就是强制使用普通方式,仍然像上面同样,在配置文件中加上如下参数:
other_args="--insecure-registry 192.168.0.232:5000"
重启 docker 服务,而后 pull:
[root@sta docker]# docker pull 192.168.0.232:5000/busybox Pulling repository 192.168.0.232:5000/busybox 437595becdeb: Download complete 437595becdeb: Pulling image (latest) from 192.168.0.232:5000/busybox Status: Image is up to date for 192.168.0.232:5000/busybox:latest