zoukankan      html  css  js  c++  java
  • docker19.03搭建私有容器仓库

    一,启动docker后,搜索registry

    [root@localhost source]# systemctl start docker
    [root@localhost source]# docker search registry
    NAME                                 DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
    registry                             The Docker Registry 2.0 implementation for s…   2873                [OK]      

    说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest

             对应的源码可以访问这里获取: https://github.com/liuhongdi/

     说明:作者:刘宏缔 邮箱: 371125307@qq.com

    二,下载registry容器

    1,下载

    [root@localhost docker]# docker pull registry

    2,查看本地的镜像:

    [root@localhost docker]# docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    registry            latest              708bc6af7e5e        6 weeks ago         25.8MB

    三,启动registry

    1,启动registry

    [root@localhost docker]# docker run -d -p 5000:5000 -v /data/docker/registry:/var/lib/registry --privileged=true --restart=always --name registry registry:latest
    0e48cc6c0871bf2d5a0ee0208d3e87ae0cf4706dada93c7e80133fa22f7bbaef
    [root@localhost docker]# docker ps -a
    CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
    0e48cc6c0871        registry:latest     "/entrypoint.sh /etc…"   7 seconds ago       Up 5 seconds        0.0.0.0:5000->5000/tcp   registry

    2,查看registry的ip地址

    [root@localhost docker]# docker inspect registry | grep IPAddress
                "SecondaryIPAddresses": null,
                "IPAddress": "172.17.0.2",
                        "IPAddress": "172.17.0.2",

    3,用浏览器访问5000端口,判断是否安装成功:

    这个地址:

    http://172.17.0.2:5000/v2/

    四,查看私有库的镜像列表:

    [root@localhost docker]# curl http://172.17.0.2:5000/v2/_catalog
    {"repositories":[]}

    五,我们制作一个基于centos8的nfs的镜像

    参见:

    docker19.03制作一个基于centos8的带有nfs4服务的镜像
    地址:https://www.cnblogs.com/architectforest/p/12495958.html

    六,上传一个镜像到私有库

    我们把上面制作的镜像上传到我们搭建的私有库

    1,给当前镜像打上tag:

    [root@localhost ~]# docker tag nfsnginx:0.1 172.17.0.2:5000/nfsnginx:0.1

    查看打tag后的效果

    [root@localhost ~]# docker images | grep nfsnginx
    172.17.0.2:5000/nfsnginx   0.1                 fa72df9fb744        3 hours ago         328MB
    nfsnginx                   0.1                 fa72df9fb744        3 hours ago         328MB

    2,开始push

    [root@localhost ~]# docker push 172.17.0.2:5000/nfsnginx:0.1
    The push refers to repository [172.17.0.2:5000/nfsnginx]
    Get https://172.17.0.2:5000/v2/: http: server gave HTTP response to HTTPS client

    这个报错是什么?

    Docker与Docker Registry交互默认使用https协议,

    我们搭建的Docker Registry只提供http服务,

    当和Registry私有仓库交互时会失败,

    为解决这个问题,我们启动Docker时配置Registry不安全选项即可

    说明:要用防火墙限制私有库的访问,不允许端口从公网上随便访问

    3,解决上面的那个报错:

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

    增加一行:

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

    看例子:

    [root@localhost ~]# more /etc/docker/daemon.json 
    {
        "registry-mirrors":["https://o3trwnyj.mirror.aliyuncs.com"],
        "insecure-registries":["172.17.0.2:5000"]
    }

    然后重启docker服务:

    [root@localhost ~]# systemctl restart docker

    并再次启动容器

    [root@localhost ~]# docker start registry
    registry

    4,再次push:

    [root@localhost ~]# docker push 172.17.0.2:5000/nfsnginx:0.1
    The push refers to repository [172.17.0.2:5000/nfsnginx]
    28dd39094cf0: Pushed 
    0683de282177: Pushed 
    0.1: digest: sha256:98417504960cfd0c3ddbb61f18ac8ed7e4737136cc8640f1d24c0f8f5d4eb1fe size: 741

    5,上传是否成功?我们从浏览器访问这个地址:

    http://172.17.0.2:5000/v2/_catalog

    响应内容为:

    {"repositories":["nfsnginx"]}

    可以确认已上传成功

    6,查看已上传镜像的tag列表:

    从浏览器访问这个地址:

    http://172.17.0.2:5000/v2/nfsnginx/tags/list

    说明:nfsnginx是我们所上传的镜像的名字

    七,从私有库下载一个镜像

    从另一台安装有docker的服务器上测试:

    1,执行docker的pull命令:

    [root@localhost liuhongdi]# docker pull 192.168.1.8:5000/nfsnginx:0.1
    Error response from daemon: Get https://192.168.1.8:5000/v2/: http: server gave HTTP response to HTTPS client

    说明:192.168.1.8是上面搭建registry的docker宿主机的ip

    2,解决方法同上:

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

    增加一行:

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

    然后重启docker:

    [root@localhost liuhongdi]# systemctl restart docker

    3,再次测试:

    [root@localhost liuhongdi]# docker pull 192.168.1.8:5000/nfsnginx:0.1
    0.1: Pulling from nfsnginx
    8a29a15cefae: Already exists 
    b3f2d668510c: Pull complete 
    Digest: sha256:98417504960cfd0c3ddbb61f18ac8ed7e4737136cc8640f1d24c0f8f5d4eb1fe
    Status: Downloaded newer image for 192.168.1.8:5000/nfsnginx:0.1

    4,查看下载是否成功

    [root@localhost liuhongdi]# docker images | grep nfsnginx
    192.168.1.8:5000/nfsnginx   0.1                 fa72df9fb744        4 hours ago         328MB

     八,查看docker的版本 

    [root@localhost source]# docker --version
    Docker version 19.03.7, build 7141c19
  • 相关阅读:
    序列合并(luogu 1631)题解
    邮递员送信(luogu 1629)题解
    敲砖块(codevs 1257)题解
    货车运输(codevs 3287)题解
    分布式服务框架 Zookeeper -- 管理分布式环境中的数据
    dubbo学习
    第一章 1.20 多线程基础
    第一章 1.19 网络编程基础
    练习 : 面向对象
    练习 : 正则表达式
  • 原文地址:https://www.cnblogs.com/architectforest/p/12496007.html
Copyright © 2011-2022 走看看