记录日常工作关于系统运维,虚拟化云计算,数据库,网络安全等各方面问题。
 
0

 搭建Docker私有仓库

 

 准备两台虚拟机,两台机器上都配好yum源,安装好docker,设置好docker加速器。

Docker客户端:192.168.1.160;Docker私有仓库服务器:192.168.1.161

[root@k8s ~]# docker search registry     
INDEX       NAME                                           DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
docker.io   docker.io/registry                             The Docker Registry 2.0 implementation for...   2716      [OK]       
docker.io   docker.io/distribution/registry                WARNING: NOT the registry official image!!...   58                   [OK]
docker.io   docker.io/stefanscherer/registry-windows       Containerized docker registry for Windows ...   26                   
docker.io   docker.io/budry/registry-arm                   Docker registry build for Raspberry PI 2 a...   18                   
docker.io   docker.io/deis/registry                        Docker image registry for the Deis open so...   12                   
docker.io   docker.io/anoxis/registry-cli                  You can list and delete tags from your pri...   8                    [OK]
docker.io   docker.io/sixeyed/registry                     Docker Registry 2.6.0 running on Windows -...   8                    
docker.io   docker.io/vmware/registry                                                                      5                    
docker.io   docker.io/allingeek/registry                   A specialization of registry:2 configured ...   4                    [OK]
docker.io   docker.io/jc21/registry-ui                     A nice web interface for managing your Doc...   4                    
docker.io   docker.io/pallet/registry-swift                Add swift storage support to the official ...   4                    [OK]
docker.io   docker.io/conjurinc/registry-oauth-server      Docker registry authn/authz server backed ...   1                    
docker.io   docker.io/goharbor/registry-photon                                                             1                    
docker.io   docker.io/ibmcom/registry                      Docker Image for IBM Cloud private-CE (Com...   1                    
docker.io   docker.io/metadata/registry                    Metadata Registry is a tool which helps yo...   1                    [OK]
docker.io   docker.io/webhippie/registry                   Docker images for Docker Registry               1                    [OK]
docker.io   docker.io/concourse/registry-image-resource                                                    0                    
docker.io   docker.io/convox/registry                                                                      0                    
docker.io   docker.io/dwpdigital/registry-image-resource   Concourse resource type                         0                    
docker.io   docker.io/ghmlee/registrybot                   registrybot                                     0                    [OK]
docker.io   docker.io/gisjedi/registry-proxy               Reverse proxy of registry mirror image gis...   0                    
docker.io   docker.io/kontena/registry                     Kontena Registry                                0                    
docker.io   docker.io/lorieri/registry-ceph                Ceph Rados Gateway (and any other S3 compa...   0                    
docker.io   docker.io/upmcenterprises/registry-creds                                                       0                    
docker.io   docker.io/zoined/registry                      Private Docker registry based on registry:2     0  


  1. 在服务端192.168.1.161上拉取仓库镜像:registry 

                 
    [root@k8s ~]# docker pull webhippie/registry
    Using default tag: latest
    Trying to pull repository docker.io/webhippie/registry ...
    latest: Pulling from docker.io/webhippie/registry
    b8141ae1f663: Pull complete
    13567e09b640: Pull complete
    aaeefa8fabe4: Pull complete
    b83abbbdca23: Pull complete
    2314799e1038: Pull complete
    4fc129cc61df: Pull complete
    44b981355f00: Pull complete
    e04c698eb149: Pull complete
    401e5b270728: Pull complete
    Digest: sha256:bba865b672c066f0276725f8c617bf824fbade6ec59764143b4e68919e4f3a80
    Status: Downloaded newer image for docker.io/webhippie/registry:latest


在服务端192.168.1.161运行docker私有仓库

[root@k8s ~]# docker run -d -v /registry:/var/lib/registry -p 5000:5000 --restart=always --privileged=true --name registry webhippie/registry:latest


8e91fd9ab3c7801792c7e3e6388021f93989872d545754faf9b21afea6135d58

如果成功执行,则表示我们的docker私有仓库搭建成功。

下面对这条命令的部分内容做下说明。

/registry表示宿主机目录,该目录如果不存在会自动创建。

docker -v 宿主机目录:容器目录

在网上看到的解释:

把宿主机的目录挂载到容器中

或者

把docker 容器中某目录的数据 加载到 宿主机的某个目录

这样做的目的是为了防止docker私有仓库这个容器被删除时,仓库里的镜像也会被删除。

3.在客户端制作镜像

以hello-world为例,先把它拉取下来

[root@localhost ~]# docker pull hello-world

给hello-world镜像打个tag,表示新的版本

[root@localhost ~]# docker tag hello-world 192.168.1.161:5000/hello-world:latest

4.将新的hello-world镜像上传到私有仓库

[root@localhost ~]# docker push 192.168.1.161:5000/hello-world:latest

发现会报以下错误:

The push refers to a repository [192.168.1.161:5000/hello-world]
Get https://192.168.1.161:5000/v1/_ping: http: server gave HTTP response to HTTPS client

原因是docker私有仓库服务器,默认是基于https传输的,所以我们需要在客户端192.168.1.160做相关设置,不使用https传输

[root@localhost ~]# vi /etc/docker/daemon.json

将下面的代码放进去保存并退出。

"insecure-registries":["192.168.1.161:5000"]

最终如下所示:

{        "registry-mirrors": ["https://njrds9qc.mirror.aliyuncs.com"],        "insecure-registries":["192.168.1.161:5000"]
}

依次执行下面两条命令,重新启动docker:

[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl restart docker

再次执行推送命令:

[root@localhost ~]# docker push 192.168.1.161:5000/hello-world:latest

5.在私有仓库192.168.1.161查看上传的镜像

[root@localhost repositories]# ls /registry/docker/registry/v2/repositories

或者在客户端执行以下命令查看:

[root@localhost ~]# curl http://192.168.1.161:5000/v2/_catalog

会输出:

{"repositories":["hello-world"]}

好,大功告成。

 

参考地址:

https://blog.csdn.net/mmd0308/article/details/77162004

https://www.cnblogs.com/Javame/p/7389093.html




转载请标明出处【 搭建Docker私有仓库】。

《www.micoder.cc》 虚拟化云计算,系统运维,安全技术服务.

网站已经关闭评论