• docker探索-docker私有仓库搭建(九)


    前言

      本文讲解搭建docker的私有仓库,和Mavan的管理一样,Dockers不仅提供了一个中央仓库,同时也允许我们使用registry搭建本地私有仓库

    一、环境

    ip 主机名 操作系统 角色
    192.168.6.131 node2.jacky.com 7.3.1611 客户端
    192.168.6.132 node3.jacky.com 7.3.1611 私有仓库

    二、搭建

    2.1、在132机器上下载registry镜像

    docker pull registry

    2.2、防火墙添加运行5000端口

    iptables -I INPUT 1 -p tcp --dport 5000 -j ACCEPT

    2.3、创建registry容器,并启动

    docker run -d -p 5000:5000 --privileged=true -v /opt/registry:/tmp/registry registry  

    说明:

    • 默认情况下,会将仓库存放于容器内的/tmp/registry目录下,这样如果容器被删除,则存放于容器中的镜像也会丢失,所以我们一般情况下会指定本地一个目录挂载到容器内的/opt/registry下
    • –privileged=true :CentOS7中的安全模块selinux把权限禁掉了,参数给容器加特权,不加上传镜像会报权限错误(OSError: [Errno 13] Permission denied: ‘/tmp/registry/repositories/liibrary’)或者(Received unexpected HTTP status: 500 Internal Server Error)错误

    2.4、客户端修改/etc/sysconfig/docker文件,在后面追加,不加会报https证书错误,然后重启docker

    OPTIONS='--insecure-registry 192.168.6.132:5000'    #CentOS 7系统
    other_args='--insecure-registry 192.168.6.132:5000' #CentOS 6系统

    三、测试

    3.1、把本地镜像jacky/mytomcat:1.0的tag

    docker tag 3d95a80ccbda 192.168.6.132:5000/jacky/mytomcat:1.2

    结果如下

     

    注意:前缀一定要私有仓库Ip:端口/,否则上传会报错

    3.2、上传镜像192.168.6.132:5000/jacky/mytomcat:1.2到私有仓库

    docker push 192.168.6.132:5000/jacky/mytomcat:1.2

    3.3、删除该镜像,然后重新下载该镜像

    [root@node2 jacky]# docker rmi 192.168.6.132:5000/jacky/mytomcat:1.2
    Untagged: 192.168.6.132:5000/jacky/mytomcat:1.2
    Untagged: 192.168.6.132:5000/jacky/mytomcat@sha256:da9f7e620ade2c1fb3c4c516cf6c8303045699dba58759f4cf15408a2858228f
    [root@node2 jacky]# docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    jacky/mytomcat      1.0                 3d95a80ccbda        6 days ago          655.3 MB
    jacky/mytomcat      1.1                 3d95a80ccbda        6 days ago          655.3 MB
    jacky/ubuntu        14.05               ff41e3aca80b        7 days ago          209.1 MB
    jacky/ubuntu        dev                 ff41e3aca80b        7 days ago          209.1 MB
    jacky/centos        v3                  67a8ec824059        7 days ago          326.3 MB
    jacky/ubuntu        v2                  9634808b727b        8 days ago          137.2 MB
    docker.io/nginx     latest              40960efd7b8f        2 weeks ago         108.4 MB
    docker.io/ubuntu    14.04               3aa18c7568fc        2 weeks ago         188 MB
    docker.io/httpd     latest              74ad7f48867f        2 weeks ago         177.3 MB
    docker.io/debian    wheezy              f47fe1c60a2f        2 weeks ago         85.13 MB
    docker.io/busybox   latest              6ad733544a63        2 weeks ago         1.129 MB
    docker.io/centos    7.2.1511            0a2bad7da9b5        2 weeks ago         194.6 MB
    docker.io/ubuntu    15.10               9b9cb95443b5        16 months ago       137.2 MB
    [root@node2 jacky]# docker pull 192.168.6.132:5000/jacky/mytomcat:1.2
    Trying to pull repository 192.168.6.132:5000/jacky/mytomcat ... 
    sha256:da9f7e620ade2c1fb3c4c516cf6c8303045699dba58759f4cf15408a2858228f: Pulling from 192.168.6.132:5000/jacky/mytomcat
    Digest: sha256:da9f7e620ade2c1fb3c4c516cf6c8303045699dba58759f4cf15408a2858228f
    Status: Downloaded newer image for 192.168.6.132:5000/jacky/mytomcat:1.2
    [root@node2 jacky]# docker images
    REPOSITORY                          TAG                 IMAGE ID            CREATED             SIZE
    192.168.6.132:5000/jacky/mytomcat   1.2                 3d95a80ccbda        6 days ago          655.3 MB
    jacky/mytomcat                      1.0                 3d95a80ccbda        6 days ago          655.3 MB
    jacky/mytomcat                      1.1                 3d95a80ccbda        6 days ago          655.3 MB
    jacky/ubuntu                        14.05               ff41e3aca80b        7 days ago          209.1 MB
    jacky/ubuntu                        dev                 ff41e3aca80b        7 days ago          209.1 MB
    jacky/centos                        v3                  67a8ec824059        7 days ago          326.3 MB
    jacky/ubuntu                        v2                  9634808b727b        8 days ago          137.2 MB
    docker.io/nginx                     latest              40960efd7b8f        2 weeks ago         108.4 MB
    docker.io/ubuntu                    14.04               3aa18c7568fc        2 weeks ago         188 MB
    docker.io/httpd                     latest              74ad7f48867f        2 weeks ago         177.3 MB
    docker.io/debian                    wheezy              f47fe1c60a2f        2 weeks ago         85.13 MB
    docker.io/busybox                   latest              6ad733544a63        2 weeks ago         1.129 MB
    docker.io/centos                    7.2.1511            0a2bad7da9b5        2 weeks ago         194.6 MB
    docker.io/ubuntu                    15.10               9b9cb95443b5        16 months ago       137.2 MB
    [root@node2 jacky]# 

    可以看到,重新下载了

    四、查询私有仓库镜像

    在Private Registry2中查看或检索Repository或images,将不能用docker search,会报下边的错误

    [root@node2 jacky]# docker search 192.168.6.132:5000/
    Error response from daemon: Unexpected status code 404
    [root@node2 jacky]# curl  http://192.168.6.132:5000/v2/_catalog
    {"repositories":["jacky/mytomcat"]}
    [root@node2 jacky]# curl  http://192.168.6.132:5000/v2/jacky/mytomcat/tags/list
    {"name":"jacky/mytomcat","tags":["1.2"]}
    [root@node2 jacky]# 
  • 相关阅读:
    1040. Moving Stones Until Consecutive II
    999. Available Captures for Rook
    1035. Uncrossed Lines
    1031. Maximum Sum of Two Non-Overlapping Subarrays
    配置启动挂载:fstab文件详解
    Linux下某个进程CPU占用率高分析方法
    linux中uptime命令查看linux系统负载
    强大的strace命令用法详解
    公司内网,配置代理以后无法使用yum源
    sshd_config配置文件
  • 原文地址:https://www.cnblogs.com/520playboy/p/7889647.html
Copyright © 2020-2023  润新知