• Docker 搭建本地Registry


    Docker已经将Registry开源,Registry本身也是一个容器。

    1. 修改配置/etc/docker/daemon.json,去掉docker默认的https的访问
       里面的内容是一个json对象,加上一项insecure-registries:

    {
    "insecure-registries":["172.16.65.150:5000"],
    "registry-mirrors": ["http://2555a638.m.daocloud.io"]
    }

    2. 启动Registry容器

    root@Docker001:~# docker run --name registry -d -p 5000:5000 -v /myregistry/:/var/lib/registry registry:2
    Unable to find image 'registry:2' locally
    2: Pulling from library/registry
    81033e7c1d6a: Pull complete 
    b235084c2315: Pull complete 
    c692f3a6894b: Pull complete 
    ba2177f3a70e: Pull complete 
    a8d793620947: Pull complete 
    Digest: sha256:6cd209f81e188e8eaa13fad9b670fb1a4e9c7776a73b3881b69834fe5ddfb193
    Status: Downloaded newer image for registry:2
    385252aac02931701c4cae4233d1b12447b5b8b98ba6b337121d2f4a03e78709
    root@Docker001:~# docker ps
    CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
    385252aac029        registry:2          "/entrypoint.sh /e..."   9 seconds ago       Up 8 seconds        0.0.0.0:5000->5000/tcp   registry

    3. 测试Registry是否工作正常

    root@Docker001:~# curl http://172.16.65.150:5000/v2/_catalog
    {"repositories":[]}
    root@Docker001:~# 

     只要返回值为 {"repositories":[]} 表示工作正常。

    4. 给本地Image打上本地Registry标签

    root@Docker001:~# docker tag centos-with-vim 172.16.65.150:5000/centos-with-vim
    root@Docker001:~# docker images
    REPOSITORY                              TAG                 IMAGE ID            CREATED             SIZE
    centos-with-vim                         latest              c00312958340        5 days ago          359 MB
    172.16.65.150:5000/centos-with-vim      latest              c00312958340        5 days ago          359 MB
    httpd                                   latest              01154c38b473        2 weeks ago         177 MB
    debian                                  latest              1b3ec9d977fb        2 weeks ago         100 MB
    registry                                2                   d1fd7d86a825        7 weeks ago         33.3 MB
    centos                                  latest              ff426288ea90        7 weeks ago         207 MB
    hello-world                             latest              f2a91732366c        3 months ago        1.85 kB
    vincenshen/hello-world                  v1                  f2a91732366c        3 months ago        1.85 kB
    172.16.65.150:5000/hello-world          latest              f2a91732366c        3 months ago        1.85 kB
    docker001:5000/vincenshen/hello-world   v1                  f2a91732366c        3 months ago        1.85 kB
    django                                  latest              eb40dcf64078        14 months ago       436 MB
    root@Docker001:~# 

    在镜像的前面加上了运行 registry 的主机名称和端口。
    镜像名称由 repository 和 tag 两部分组成。而 repository 的完整格式为:[registry-host]:[port]/[username]/xxx
    只有 Docker Hub 上的镜像可以省略 [registry-host]:[port] 。

    5. 上传Image到Registry

    root@Docker001:~# docker push 172.16.65.150:5000/centos-with-vim
    The push refers to a repository [172.16.65.150:5000/centos-with-vim]
    b00cb99cc959: Pushed 
    e15afa4858b6: Pushed 
    latest: digest: sha256:cc103061080dde196f30aa3cb2a129a3be90dd882c0542f27d44509705802544 size: 741

    6. 查看Registry中的Image信息

    root@Docker001:~# curl http://172.16.65.150:5000/v2/_catalog
    {"repositories":["centos-with-vim"]}
    
    root@Docker001:~# curl http://172.16.65.150:5000/v2/centos-with-vim/tags/list
    {"name":"centos-with-vim","tags":["latest"]}

    7. 删除Registry中的Image

     删除镜像

    docker exec <Registry-容器名> rm -rf /var/lib/registry/docker/registry/v2/repositories/<镜像名>

     清理配置信息

     docker exec <Registry-容器名> bin/registry garbage-collect /etc/docker/registry/config.yml

    更多详细配置https://docs.docker.com/registry/configuration

  • 相关阅读:
    浏览器报错:unexpected end of input 解决方法
    MySQL 分库分表方案,总结的非常好!
    打给比较形象的比方,就是你拿着大白菜去大街上卖。这大白菜就你自己(预估自己的价格:价格喊高了,把白菜价当灵芝价卖,把买家都吓跑了,也就无人问津了。报价过低,则委屈了自己),要提前写出月薪范围,节省双方时间
    一张图弄明白开源协议-GPL、BSD、MIT、Mozilla、Apache和LGPL 之间的区别
    一个简单的C++性能测试工具(ms级别)
    VS2005下第一个ATL
    Boost::thread库的使用
    简易安装python统计包
    pip安装包报错:Microsoft Visual C++ 9.0 is required Unable to find vcvarsall.bat
    Parallel.Invoke并行你的代码
  • 原文地址:https://www.cnblogs.com/vincenshen/p/8490545.html
Copyright © 2020-2023  润新知