实验环境:
本地仓库域名:registry.cmh.cn
本地仓库:192.168.1.110
docker客户端:192.168.1.111
使用官方镜像创建registry仓库容器:
下载官方registry镜像:
创建registry仓库容器:
|
1
2
3
4
5
|
//
以上命令会创建一个名为registry的容器,并把容器中的5000端口映射到宿主机的5000端口上,并把容器中的
/tmp/registry
目录挂载到本地
/opt/data/registry
目录。
"\"docker-registry server\""
|
查看当前已有的镜像:
![2.PNG?version=1&modificationDate=1456908]()
将centos:web镜像tag为192.168.1.110:5000/centos_web,并尝试上传到本地仓库192.168.1.110:5000。
![1.PNG?version=17&modificationDate=145690]()
提示报错,这是由于从docker1.3.2版本开始,docker registry开始默认使用https方式访问,所以这里必须配置ssl auth验证。当然,也可以关闭https模式,使用简单的不验证模式,即insecure模式。
配置registry insecure模式:
在启动时添加--insecure-registry参数,如下:
#vi /etc/init.d/docker
![3.PNG?version=1&modificationDate=1456908]()
#service docker restart
修改普通模式后,push正常。
![4.PNG?version=1&modificationDate=1456908]()
查看私有仓库中的镜像,可以查到刚刚上传的镜像:
![5.png?version=1&modificationDate=1456908]()
配置registry https模式,结合nginx:
1:首先,配置nginx的https功能,并指定本地仓库的域名。
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
upstream docker-registry {
server 127.0.0.1:5000;
}
server {
listen 443;
server_name registry.cmh.cn;
ssl on;
ssl_certificate
/etc/ssl/certs/nginx
.crt;
ssl_certificate_key
/etc/ssl/private/nginx
.key;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
client_max_body_size 0;
chunked_transfer_encoding on;
location / {
auth_basic
"Restricted"
;
auth_basic_user_file docker-registry.htpasswd;
proxy_pass http:
//docker-registry
;
}
location
/_ping
{
auth_basic off;
proxy_pass http:
//docker-registry
;
}
location
/v1/_ping
{
auth_basic off;
proxy_pass http:
//docker-registry
;
}
}
|
2:配置ssl证书,以及密码文件。
生成根密钥文件:
![6.PNG?version=1&modificationDate=1456908]()
生成根证书:
![7.png?version=1&modificationDate=1456908]()
为nginx生成ssl密钥,以及证书签署请求:
![8.png?version=1&modificationDate=1456908]()
私有CA根据请求来签发证书:
![9.png?version=1&modificationDate=1456908]()
把证书复制到nginx相关的验证目录:
创建验证登陆的密码文件:
|
1
2
3
4
5
|
New password:
Re-
type
new password:
Adding password
for
user cmh
|
从本地docker登陆,尝试push镜像:
|
1
2
3
4
5
|
{
"num_results"
: 2,
"query"
:
""
,
"results"
: [{
"description"
:
""
,
"name"
:
"library/centos_web"
}, {
"description"
:
""
,
"name"
:
"library/registry"
}]}
|
![10.PNG?version=1&modificationDate=145690]()
可以看到仓库中已经包含了新push的images:
|
1
2
|
{
"num_results"
: 2,
"query"
:
""
,
"results"
: [{
"description"
:
""
,
"name"
:
"library/centos_web"
}, {
"description"
:
""
,
"name"
:
"library/registry"
}]}
|
从客户端pull和push镜像:
110:拷贝证书到客户端
111:
登陆,并从本地仓库pull一个镜像:
![11.png?version=1&modificationDate=145690]()
上传一个tag过的镜像到本地仓库:
![12.png?version=1&modificationDate=145690]()
本文转自 icenycmh 51CTO博客,原文链接:http://blog.51cto.com/icenycmh/1746833,如需转载请自行联系原作者