• docker_info_05_registry 仓库管理


    docker_info_05_registry 仓库管理

    5.1.关于 docker 的私有仓库 Docker Hub

    docker 制作好镜像后,默认存放在本地,只可以本机使用,其他服务器无法使用
    如果想其他服务器也能使用该镜像就需要创建一个 docker 仓库,其他服务器使用的时候只需要 pull 下来即可使用
    Docker 默认提供了一个仓库叫 docker registry ,使用 https 进行验证,
    Registry 在 git 上分为老代码库和新代码库,老代码 push,pull 存在性能问题,新代码库采用 go 语言编写大大优化了 push 和 pull 的效率。
    docker 将私有 hub 的环境打包在 registry image 中
    tag 为 latest 的版本为 0.9.1 版本,这里直接采用 2.1.1 版本
    

    5.2.创建私有 registry 库

    1.1.搜索 docker ,下载 registry 镜像
    docker search docker
    docker pull registry
    docker images
    
    1.2.使用 registry 镜像启动容器
    # 建议修改私有库镜像的保存位置,方便私有库镜像管理:
    1)registry 服务默认会将上传到私有库的镜像保存在容器的 /var/lib/registry 目录,
    2)将指定的宿主机目录 /data/docker/registry 挂载到 registry 容器的 /var/lib/registry 目录即可
    
    # registry 服务默认使用 5000 端口,检查是否有其他进程占用
    netstat -anptl|grep 5000
    
    # 使用 registry 镜像启动容器,将宿主机的 5000 端口绑定到容器的 5000 端口
    mkdir -p /data/docker/registry
    docker run -d -p 5000:5000 -v /data/docker/registry:/var/lib/registry --restart=always --name registry-01 -h registry-01 registry
    ------------------------------------
    [root@zuiyoujie tools]# docker run -d -p 5000:5000 -v /data/docker/registry:/var/lib/registry --restart=always --name registry-01 -h registry-01 registry
    0225471d3a903e135c2ea81bb743686671411491bbe8280966fb2b79363724cb
    [root@zuiyoujie tools]# docker ps -a
    CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
    0225471d3a90        registry            "/entrypoint.sh /etc…"   14 seconds ago      Up 13 seconds       0.0.0.0:5000->5000/tcp   registry-01
    ------------------------------------
    
    # 可以通过浏览器进行访问测试:返回一个中括号
    curl 192.168.1.81:5000/v2
    ------------------------------------
    [root@zuiyoujie tools]# curl 192.168.1.81:5000/v2
    <a href="/v2/">Moved Permanently</a>.
    ------------------------------------
    
    1.3.给镜像做版本标记 tag
    ------------------------------------
    # 用法:
    docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
    docker tag $ID $IP:$port/$name
    
    # 命令实例:
    docker pull hello-world         # 使用hello-world镜像进行演示
    docker tag hello-world 192.168.1.81:5000/hello-world    # 标记为 latest 也就是 v2 版本
    # docker tag centos 192.168.1.81:5000/mycentos
    curl http://192.168.1.81:5000/v2/_catalog
    ------------------------------------
    
    # 实例演示:
    -------------------------------------
    [root@zuiyoujie tools]# docker tag hello-world 192.168.1.81:5000/hello-world:v1
    [root@zuiyoujie tools]# docker images
    REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE
    centos                          latest              5182e96772bf        3 weeks ago         200MB
    192.168.1.81:5000/hello-world   latest              2cb0d9787c4d        7 weeks ago         1.85kB
    hello-world                     latest              2cb0d9787c4d        7 weeks ago         1.85kB
    registry                        latest              b2b03e9146e1        7 weeks ago         33.3MB
    [root@zuiyoujie tools]# curl http://192.168.1.81:5000/v2/_catalog
    {"repositories":[]}
    -------------------------------------
    
    1.4.上传某个镜像到自建仓库
    -------------------------------------
    # 命令语法:
    docker push [OPTIONS] NAME[:TAG]
    
    # 修改 docker 配置,修改仓库地址为自建仓库
    echo "{ "insecure-registries":["192.168.1.81:5000"] }" >/etc/docker/daemon.json
    docker push 192.168.1.81:5000/hello-world:v3
    curl http://192.168.1.81:5000/v2/_catalog
    -------------------------------------
    
    实例演示:
    ------------------------------------
    [root@zuiyoujie tools]# echo "{ "insecure-registries":["192.168.1.81:5000"] }" >/etc/docker/daemon.json
    [root@zuiyoujie tools]# docker push 192.168.1.81:5000/hello-world
    The push refers to repository [192.168.1.81:5000/hello-world]
    ee83fc5847cb: Pushed
    latest: digest: sha256:aca41a608e5eb015f1ec6755f490f3be26b48010b178e78c00eac21ffbe246f1 size: 524
    [root@zuiyoujie tools]# curl http://192.168.1.81:5000/v2/_catalog
    {"repositories":["hello-world"]}                    # 可以看到上传的镜像
    [root@zuiyoujie tools]# ll /data/docker/registry/   # 同时可以看到镜像文件
    总用量 0
    drwxr-xr-x 3 root root 21 8月  30 00:08 docker
    ------------------------------------
    
    • 报错处理:
    -------------------------------------
    [root@zuiyoujie tools]# docker push 192.168.1.81:5000/hello-world
    The push refers to repository [192.168.1.81:5000/hello-world]
    Get https://192.168.1.81:5000/v2/: http: server gave HTTP response to HTTPS client
    -------------------------------------
    
    # 报错原因:
    Docker 从 1.3.X 之后 registry 默认使用的是 https,由于客户端采用 https,docker registry 未采用 https 服务所以出错
    
    # 解决方法:
    1)把客户对地址“192.168.1.81:5000”请求改为http,测试,不成功
    2)修改配置文件/etc/systemconfig/docker重启docker,但本版本不存在该文件,创建对应文件进行操作也不成功
    DOCKER_OPTS="--insecure-registry 192.168.1.81:5000
    3)可以在”/etc/docker/“目录下,创建”daemon.json“文件,写入以下内容,重启docker生效
    { "insecure-registries":["192.168.1.81:5000"] }
    
    other_args="-H tcp://0.0.0.0:235 -H unix:///var/run/docker.sock"2
    other_args="--insecure-registry 192.168.1.68:5000  -H tcp://0.0.0.0:235 -H unix:///var/run/docker.sock"
    

    1.5.测试registry私有库

    1)删除hello-world镜像
    docker rmi hello-world
    -------------------------------------
    [root@zuiyoujie tools]# docker rmi hello-world
    Untagged: hello-world:latest
    Untagged: hello-world@sha256:4b8ff392a12ed9ea17784bd3c9a8b1fa3299cac44aca35a85c90c5e3c7afacdc
    [root@zuiyoujie tools]# docker images         
    REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE
    ubuntu                          latest              16508e5c265d        6 days ago          84.1MB
    centos                          latest              5182e96772bf        3 weeks ago         200MB
    192.168.1.81:5000/hello-world   latest              2cb0d9787c4d        7 weeks ago         1.85kB
    registry                        latest              b2b03e9146e1        7 weeks ago         33.3MB
    -------------------------------------
    
    2)从本地registry库下载hello-world镜像
    docker pull 192.168.1.81:5000/hello-world
    -------------------------------------
    [root@zuiyoujie tools]# docker pull 192.168.1.81:5000/hello-world
    Using default tag: latest
    latest: Pulling from hello-world
    Digest: sha256:aca41a608e5eb015f1ec6755f490f3be26b48010b178e78c00eac21ffbe246f1
    Status: Image is up to date for 192.168.1.81:5000/hello-world:latest
    [root@zuiyoujie tools]# docker images
    REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE
    ubuntu                          latest              16508e5c265d        6 days ago          84.1MB
    centos                          latest              5182e96772bf        3 weeks ago         200MB
    192.168.1.81:5000/hello-world   latest              2cb0d9787c4d        7 weeks ago         1.85kB
    registry                        latest              b2b03e9146e1        7 weeks ago         33.3MB
    -------------------------------------
    
    ############  docker web UI #################
    
    使用yum安装docker-registry,启动:systemctl restart docker-registry   ;systemctl enable docker-registry
    在docker服务器上使用命令启动:/usr/bin/docker-current daemon --insecure-registry=192.168.1.61:5000 &
    
    docker image tag hello-world 192.168.1.81:5000/hello-world:v3
    docker container stop registry && docker container rm -v registry
    
    挂在本地目录到 docker 下的tomcat目录下
    docker run -d --privileged=true -p 18080:8080 --name tomcat-web -v /root/soft/tomcat/tomcat-web/:/usr/local/tomcat/ 192.168.1.61:5000/java /usr/local/tomcat/bin/catalina.sh run
    
    项目构建 redis:
    docker run -d --privileged=true --net=host --name redis-cluster-1 -v /root/soft/redis/redis-1/:/usr/local/redis/ 192.168.1.61:5000/java /usr/local/redis/src/redis-server  /usr/local/redis/redis.conf
    
    挂载目录启动
    docker run -it --privileged=true -v /home/docker/soft/:/soft --name test icentos /bin/bash
    
    docker run -d -p 8080:8080 -v /home/docker/workdir/tomcat/:/usr/local/tomcat --privileged=true --name tomcat tomcat8
    

    END

  • 相关阅读:
    Hard 随机洗牌函数 @CareerCup
    Hard 随机选择subset @CareerCup
    Hard 计算0到n之间2的个数 @CareerCup
    Django admin进阶
    hdu 5630 Rikka with Chess
    PHP 表单验证
    PHP 表单验证
    PHP 表单验证
    PHP 表单验证
    PHP 表单处理
  • 原文地址:https://www.cnblogs.com/tssc/p/13902145.html
Copyright © 2020-2023  润新知