码迷,mamicode.com
首页 > 其他好文 > 详细

通过nginx建立docker的私有registry

时间:2015-04-17 18:38:54      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:nginx docker registry

docker registry具体应用

docker registry 是管理 docker 镜像的服务,  官方registry 地址 http://hub.docker.com ,可以让我们方便的下载预先做好的镜像。


$ docker pull centos

上面的命令就是缺省的从这个Docker官方源下载。在国内为了加快访问,也可以使用docker.cn 的服务,详细列出服务器的地址

如:


$ docker pull docker.cn/docker/centos

企业应用时基本会创建自己的私库,不仅仅是为了安全、节省大量的带宽,而且也可以有效推动内部对docker的有效利用


Docker公司的 docker registry也是开源的,可以很容易的架设自己的私有docker registry,启动时典型的docker方式,就是:


$ docker run -d -p 5000:5000 registry

使用也很简单了,下面的命令就是把官方的centos镜像放在私有的registry:


$ docker tag centos company.com:5000/centos 

$ docker push company.com:5000/centos

不过他有以下几个问题:


registry缺省没有安全权限的设置,任何人都可以pull、push,这个基本上是不能接受的。

新版本的docker需要走的https验证


可以通过nginx+registry来解决一些安全性的问题


docker.co  docker服务器的私有地址

在/etc/hosts里做地址解析(一定要做地址解析,不然后面会验证不成功的)

registry 服务器作为上游服务器处理docker镜像的最终上传和下载,用的是官方的镜像。


nginx 是一个用nginx作为反向代理服务器,通过模块提供https的ssl的认证和basic authentication,加上必要的配置,很简单可以网上查找配置内容

 larrycai/nginx-auth-proxy 。


他们之间的关系  nginx把这些https、认证服务搞定,registry关注docker的镜像服务就可以了。


启动命令


$ docker run -d --name registry -p 5000:5000 registry 

$ docker run -d --name nginx --link registry:registry -p 443:443 larrycai/nginx-auth-proxy


--name registry:这是docker的容器链接(link)技术,为了方便 nginx 容器的访问 registry(对应 --link registry:registry )


-p 5000:5000 registry 作为上游服务器,这个 5000 端口可以不用映射出来,因为所有的外部访问都是通过前端的nginx来提供,nginx 可以在私有网络访问 registry 。端口映射出来只是为了方便调试,确保查看 registry 是否独立也能工作。

-p 443:443 就是对外服务的https端口。


验证

Registry服务


先验证 registry 是否正常:


$ docker pull hello-world # 这个hello world包很小,适合做实验 

$ docker tag hello-world localhost:5000/hello-world 

$ docker push localhost:5000/hello-world 

The push refers to a repository [localhost:5000/hello-world] (len: 1) Sending image list Pushing repository localhost:5000/hello-world (1 tags) 511136ea3c5a: Image successfully pushed 7fa0dcdc88de: Image successfully pushed ef872312fe1b: Image successfully pushed Pushing tag for rev [ef872312fe1b] on {http://localhost:5000/v1/repositories/hello-world/tags/latest}


结果一切正常,registry已经能提供后端的 docker registry 服务了。



docker的HTTPS服务


现在看看nginx的https服务怎么样,先用curl命令。( larrycai:passwd 预先放置的用户和密码)


$ curl -i -k https://larrycai:passwd@docker.co


一定要在 /etc/hosts的localhost 后面加上 docker.co 



$ curl -i -k https://larrycai:passwd@docker.co

HTTP/1.1 200 OK Server: nginx/1.6.2 Date: Sat, 11 Apr 2015 09:21:18 GMT Content-Type: application/json Content-Length: 28 Connection: keep-alive Expires: -1 Pragma: no-cache Cache-Control: no-cache  "\"docker-registry server\""

说明连通了 nginx 和 registry


实际上也打开浏览器访问 https://******* , *******是docker机器的IP

通过nginx建立docker的私有registry

标签:nginx docker registry

原文地址:http://boking.blog.51cto.com/8080748/1633883

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!