导读 docker 是Linux下面的容器技术,是目前最火的开源技术之一,上次我们了解了docker的基础知识,docker的容器,仓库,镜像等,接下来我们就一起来看下本地仓库的搭建吧。
一,本地安装
# yum install -y python-devel libevent-devel python-pip gcc xz-devel 

# pip install docker-registry

也可以从 docker-registry (https://github.com/docker/docker-registry)项目下载源码进行安装。

二,使用官方 registry 镜像
# docker run -d -p 5000:5000 registry #将使用官方的 registry 镜像来启动本地的私有仓库,但是并没有启动,只是为你创建好

默认情况下,会将仓库存放于容器的 /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 镜像比较小,没有的建议先下载:

# 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的时候就会报上面的错误。

为了解决这个问题需要在启动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

原文来自:http://www.tianfeiyu.com/?p=2532编辑:田飞雨

本文地址:https://www.linuxprobe.com/docker-repo-local.html编辑:陶武杰,审核员:逄增宝

本文原创地址:https://www.linuxprobe.com/docker-repo-local.html编辑:public,审核员:暂无