使用registry搭建私有仓库

获取yum源

wget ftp://ftp.rhce.cc/k8s/* -P /etc/yum.repos.d/

拉取镜像

[root@registry ~]# docker pull    hub.c.163.com/library/registry:latest

查看镜像信息

[root@registry ~]# docker history  hub.c.163.com/library/registry:latest 
IMAGE          CREATED       CREATED BY                                      SIZE      COMMENT
751f286bc25e   4 years ago   /bin/sh -c #(nop)  CMD ["/etc/docker/registr…   0B        
<missing>      4 years ago   /bin/sh -c #(nop)  ENTRYPOINT ["/entrypoint.…   0B        
<missing>      4 years ago   /bin/sh -c #(nop) COPY file:7b57f7ab1a8cf85c…   155B      
<missing>      4 years ago   /bin/sh -c #(nop)  EXPOSE 5000/tcp              0B        
<missing>      4 years ago   /bin/sh -c #(nop)  VOLUME [/var/lib/registry]   0B        
<missing>      4 years ago   /bin/sh -c #(nop) COPY file:6c4758d509045dc4…   295B      
<missing>      4 years ago   /bin/sh -c #(nop) COPY file:b99d4fe47ad1addf…   22.8MB    
<missing>      4 years ago   /bin/sh -c set -ex     && apk add --no-cache…   5.61MB    
<missing>      4 years ago   /bin/sh -c #(nop)  CMD ["/bin/sh"]              0B        
<missing>      4 years ago   /bin/sh -c #(nop) ADD file:89e72bfc19e81624b…   4.81MB    xxxxxxxxxx [root@registry ~]# docker history  hub.c.163.com/library/registry:latest IMAGE          CREATED       CREATED BY                                      SIZE      COMMENT751f286bc25e   4 years ago   /bin/sh -c #(nop)  CMD ["/etc/docker/registr…   0B        <missing>      4 years ago   /bin/sh -c #(nop)  ENTRYPOINT ["/entrypoint.…   0B        <missing>      4 years ago   /bin/sh -c #(nop) COPY file:7b57f7ab1a8cf85c…   155B      <missing>      4 years ago   /bin/sh -c #(nop)  EXPOSE 5000/tcp              0B        <missing>      4 years ago   /bin/sh -c #(nop)  VOLUME [/var/lib/registry]   0B        <missing>      4 years ago   /bin/sh -c #(nop) COPY file:6c4758d509045dc4…   295B      <missing>      4 years ago   /bin/sh -c #(nop) COPY file:b99d4fe47ad1addf…   22.8MB    <missing>      4 years ago   /bin/sh -c set -ex     && apk add --no-cache…   5.61MB    <missing>      4 years ago   /bin/sh -c #(nop)  CMD ["/bin/sh"]              0B        <missing>      4 years ago   /bin/sh -c #(nop) ADD file:89e72bfc19e81624b…   4.81MB    [root@registry ~]# docker history  hub.c.163.com/library/registry:latest| grep VOLUME<missing>      4 years ago   /bin/sh -c #(nop)  VOLUME [/var/lib/registry]   0B

#端口:5000
#物理卷: /var/lib/registry

启动registry

[root@registry ~]# docker run -d --name myreg --restart=always -p 5000:5000 -v /myreg:/var/lib/registry hub.c.163.com/ibrary/registry 
a3257a8883f257a04a33346d284a5eb6a2dd3a1fa06c381e830cfec03fac5cd8

推送镜像

[root@cka-node1 ~]# docker push 192.168.4.100:5000/busybox:1.27
The push refers to repository [192.168.4.100:5000/busybox]
Get "https://192.168.4.100:5000/v2/": http: server gave HTTP response to HTTPS client
#此时推送会报错,是因为docker1.9开始默认使用https方式做连接,这里需要改成以http方式做连接,一下使用两种方式修改
一、
root@cka-node1 ~]# dockerd --help | grep insecure-registry
      --insecure-registry list                  Enable insecure registry communication
#打开docker启动脚本
[root@cka-node1 ~]# vim /usr/lib/systemd/system/docker.service
... ...
ExecStart=/usr/bin/dockerd --insecure-registry 192.168.4.100:5000   #添加--insecure-registry 192.168.4.100:5000 
... ... 

[root@cka-node1 ~]# systemctl daemon-reload ; systemctl restart docker  

#此时再去推送镜像就可以了
[root@cka-node1 ~]# docker push 192.168.4.100:5000/busybox:1.27 
The push refers to repository [192.168.4.100:5000/busybox]
0271b8eebde3: Pushed 
1.27: digest: sha256:91ef6c1c52b166be02645b8efee30d1ee65362024f7da41c404681561734c465 size: 527

二、
[root@cka-node2 ~]# vim /etc/docker/daemon.json
{
  "registry-mirrors": ["https://ybfg8y7z.mirror.aliyuncs.com"],
  "insecure-registries": ["192.168.4.100:5000"] #添加这一行
}

curl ip:5000/v2/_catalog #查看仓库查看仓库镜像脚本有哪些镜像

**curl ip:5000/v2/nginx/tags/list ** #查看镜像对应的标签

这里我也写了一个脚本查看仓库镜像:

Q.E.D.