环境准备

<span style="background-color: inherit;"><span style="background-color: inherit;">Docker私有仓库地址:192.168.184.40</span></span>

<span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;">Docker客户端地址:<span style="background-color: inherit;">192.168.184.15</span></span></span></span>

<span style="color: rgb(44, 44, 44); line-height: 1.5; font-family: 宋体, &quot;Arial Narrow&quot;, arial, serif; background-color: rgb(255, 255, 255);">关闭本地</span><span style="color: rgb(44, 44, 44); line-height: 1.5; font-family: 宋体, &quot;Arial Narrow&quot;, arial, serif; background-color: rgb(255, 255, 255);">selinux、</span><span style="color: rgb(44, 44, 44); line-height: 1.5; font-family: 宋体, &quot;Arial Narrow&quot;, arial, serif; background-color: rgb(255, 255, 255);">防火墙并设置开机不自启动</span>

<span style="background-color: inherit;"><font color="#ff0000" style="background-color: inherit;">一、在<span style="text-align: left; font-family: 微软雅黑; font-size: 14px; font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">192.168.184.40上</span></font></span>

<span style="background-color: inherit;">1、安装Docker-</span>
rpm -Uvh rpm -ivh https://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
<span style="background-color: inherit;">yum -y install docker-io</span>
service docker start
chkconfig docker on
&nbsp;


2、本地私有仓库registry


docker pull registry:2.5.0
<div style="background-color: inherit;">
    &nbsp;
</div>


[root@localhost ~]# docker images


REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
<div style="background-color: inherit;">
    registry&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2.5.0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ad8da6d14f6d&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3&nbsp;weeks&nbsp;ago&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;33.28&nbsp;MB
</div>


 

3、基于私有仓库镜像运行容器



默认情况下,会将仓库存放于容器内的/tmp/registry目录下,这样如果容器被删除,则存放于容器中的镜像也会丢失,
        所以我们一般情况下会指定本地一个目录挂载到容器内的/tmp/registry下,如下:

</div>

<div style="background-color: inherit;">
    <pre style="color: rgb(51, 51, 51); font-family: &quot;Source Code Pro&quot;, monospace; font-size: 14px; font-style: normal; font-weight: normal; background-color: rgba(128, 128, 128, 0.047058);">

docker run -d -p 5000:5000 -v /data/registry:/tmp/registry registry:2.5.0

        [root@localhost&nbsp;~]#&nbsp;&nbsp;docker&nbsp;ps&nbsp;-a

        CONTAINER&nbsp;ID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IMAGE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;COMMAND&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CREATED&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;STATUS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PORTS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NAMES

</div>


53941899601b        registry:2.5.0      "/entrypoint.sh /etc   13 seconds ago      Up 11 seconds       0.0.0.0:5000->5000/tcp   tender_payne   

 

4、访问私有仓库默认使用的是v2



 

 

二、在Docker客户端(192.168.184.15)上,把一个本地镜像push到私有仓库中,

1先查看一下

[root@localhost ~]# docker images centos

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

docker.io/centos    7.2.1511            686672a1d0cc        7 weeks ago         194.6 MB

 

2基础镜像打个标签

格式为 docker tag IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG]


docker tag  686672a1d0cc  192.168.184.40:5000/centos7.2.1511:0822


 

[root@localhost ~]#  docker images 

REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE

192.168.184.40/centos7.2.1511   0822                686672a1d0cc        7 weeks ago         194.6 MB

 

3修改Docker配置文件制定私有仓库url
vim&nbsp;/etc/sysconfig/docker

######添加以下内容


INSECURE_REGISTRY='–insecure-registry 192.168.184.40:5000'


#######

service docker restart

或者


systemctl daemon-reload



systemctl restart  docker.service



4提交本地镜像到私有仓库中


docker push 192.168.184.40:5000/centos7.2.1511:0822



 
<div style="background-color: inherit;">
    <font color="#2c2c2c" face="宋体, Arial Narrow, arial, serif" style="background-color: inherit;">&nbsp;5 查看一下</font>
</div>

<div style="background-color: inherit;">
    <div style="background-color: inherit;">
        curl&nbsp;<span style="background-color: inherit;">http://192.168.184.40:5000/v2/_catalog</span>
    </div>
</div>


 


[root@localhost ~]#  curl http://192.168.184.40:5000/v2/_catalog
<div style="background-color: inherit;">
    {&quot;repositories&quot;:["centos","centos7.2.1511"]}
</div>


 

 

三、从私有仓库中下载已有的镜像

1、登陆另外一台Docker客户端

2、修改Docker配置文件

vim /etc/sysconfig/docker

######添加以下内容



INSECURE_REGISTRY='–insecure-registry 192.168.184.40:5000'
        <span style="color: rgb(85, 85, 85); font-family: &quot;microsoft yahei&quot;; font-size: 14px; font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">#######</span>

</div>

    <span style="text-align: left; color: rgb(0, 0, 0); font-family: 微软雅黑; font-size: 14px; font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">service&nbsp;docker&nbsp;restart</span>

<div style="text-align: left; color: rgb(0, 0, 0); font-family: 微软雅黑; font-size: 14px; font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">
    或者
</div>

<div style="text-align: left; color: rgb(0, 0, 0); font-family: 微软雅黑; font-size: 14px; font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">
    <div style="background-color: inherit;">
        systemctl&nbsp;daemon-reload
    </div>

        systemctl&nbsp;restart&nbsp;&nbsp;docker.service

</div>

    <span style="color: rgb(44, 44, 44); font-family: 宋体, &quot;Arial Narrow&quot;, arial, serif; font-size: 14px; font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">3、从私有仓库中下载已有的镜像</span>


docker pull 192.168.184.40:5000/centos7.2.1511:0822

 


[root@localhost ~]# docker pull 192.168.184.40:5000/centos7.2.1511:0822
<div style="background-color: inherit;">
    Trying&nbsp;to&nbsp;pull&nbsp;repository&nbsp;192.168.184.40:5000/centos7.2.1511&nbsp;...&nbsp;
</div>

<div style="background-color: inherit;">
    0822:&nbsp;Pulling&nbsp;from&nbsp;192.168.184.40:5000/centos7.2.1511
</div>

<div style="background-color: inherit;">
    f19ed9d73b3e:&nbsp;Extracting&nbsp;&nbsp;69.9&nbsp;MB/69.9&nbsp;MB
</div>

<div style="background-color: inherit;">
    f19ed9d73b3e:&nbsp;Pull&nbsp;complete&nbsp;
</div>

<div style="background-color: inherit;">
    Digest:&nbsp;sha256:12c9336412cd76165d7e42906ab9a7234cecd7c4247ed92958ab4ad49644b531
</div>

<div style="background-color: inherit;">
    Status:&nbsp;Downloaded&nbsp;newer&nbsp;image&nbsp;for&nbsp;192.168.184.40:5000/centos7.2.1511:0822
</div>