使用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 ** #查看镜像对应的标签

harbor搭建私有仓库

安装docker-compose

[root@registry ~]# yum -y install docker-compose 

下载harbor

#官网地址 https://github.com/goharbor/harbor/releases

部署harbor

[root@registry harbor]# tar xf harbor-offline-installer-v2.3.2-rc1.tgz

[root@registry harbor]# cd harbor/

[root@registry harbor]# docker load -i harbor.v2.3.2.tar.gz


[root@registry harbor]# cp harbor.yml.tmpl  harbor.yml #这里他给了一个配置模板

[root@registry harbor]# vim harbor.yml
... ...
hostname: 192.168.4.100 #主机名或ip

##这里不配置https所以注释掉
# https related config
#https:
#  # https port for harbor, default is 443
#  port: 443
  # The path of cert and key files for nginx
#  certificate: /your/certificate/path
#  private_key: /your/private/key/path

harbor_admin_password: Harbor12345 #这里是登陆harbor的密码


[root@registry harbor]# ./prepare
 
 [root@registry harbor]# ./install.sh

登陆harbor

浏览器直接访问就行 http://ip
harbor.jpg

创建用户

harboruser.png

创建项目

-1代表不限制空间

harbor仓库.png
上传镜像

[root@cka-node2 ~]# docker login 192.168.4.100

[root@cka-node2 ~]# docker push 192.168.4.100/k8s/nginx

harborngixn.jpg