• 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

  • 相关阅读:
    Yarn的运行原理(执行流程)
    Hive 表类型简述
    hive 表类型
    Hadoop小知识点总结1
    电商交易项目案例
    乘用车辆和商用车辆销售数据分析
    搜狗搜索日志分析系统
    mysql group by 对多个字段进行分组
    group by
    输出GPLT
  • 原文地址:https://www.cnblogs.com/zhangrui153169/p/11858742.html
Copyright © 2020-2023  润新知