如何部署 Docker Registry 服务
如何部署 Docker Registry 服务[日期:2015-04-28]来源:livedig.com作者:KevinSJ[字体:大 中 小]
本文阐释了怎样部署私有的 Docker Registry 服务 —— 或为公司私用,或公开给其他用户使用。例如,你公司可能需要私人的 Registry 来支持持续集成(CI)。又或,你的公司可能有大量镜像方式的产品或服务,你想以公司品牌的方式来整体提供和呈现。
Docker 公共的 Registry 里维护有一个默认的 registry 镜像可以用以协助该部署过程。该 Registry 镜像对本地测试足矣,但不能用于生产环境。对于生产环境,应以 docker/distribution 为基础,自行配置并构建自定义 Registry 镜像。
注意:本文中的例子在 Ubuntu 14.04 下编写及测试。如果你在不同的操作系统中运行
Docker,你或许需要“翻译”这些命令,以适合你运行环境的需要。
官方镜像下的简单示例
本节中,将创建一个 Container 来运行 Docker 的官方 Registry 镜像。你将推送(Push)一个镜像到这个 Registry 服务器,然后再从该 Registry 中拉取(Pull)同一个镜像。
这是个很好的练习,有助于理解客户端与本地 Registry 的基本交互。
1、安装 Docker。
2、从 Docker 公共 Registry 中运行 hello-world 镜像。
$ docker run hello-world
run 命令自动从 Docker 的官方镜像库中将 hello-world 镜像 pull 下来。
3、在 localhost 上启动 Registry 服务。
$ docker run -p 5000:5000 registry:2.0
这将在 DOCKER_HOST 上启动一个 Registry 服务,并在 5000 端口监听。
4、列出镜像。
$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
registry 2.0 bbf0b6ffe9233 days ago 545.1 MB
golang 1.4 121a93c904635 days ago 514.9 MB
hello-world lateste45a5af57b003 months ago910 B
这个列表应当包括一个由先前运行而得来的 hello-world 镜像。
5、为本地 repoistory 重新标记 hello-world 镜像。
$ docker tag hello-world:latest localhost:5000/hello-mine:latest
此命令使用 NAME[:TAG] 格式为 hello-world:latest 重新打标。REGISTRYHOST在此例中是 localhost。在 Mac OSX 环境中,得把 localhost 换成 $(boot2docker ip):5000。
6、列出新镜像。
$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
registry 2.0 bbf0b6ffe9233 days ago 545.1 MB
golang 1.4 121a93c904635 days ago 514.9 MB
hello-world lateste45a5af57b003 months ago910 B
localhost:5000/hello-mine latestef5a5gf57b013 months ago910 B
可以看到,新镜像已经出现在列表中。
7、推送新镜像到本地 Registry 中。
$ docker push localhost:5000/hello-mine:latest The push refers to a repository (len: 1) e45a5af57b00: Image already exists 31cbccb51277: Image successfully pushed 511136ea3c5a: Image already exists Digest: sha256:a1b13bc01783882434593119198938b9b9ef2bd32a0a246f16ac99b01383ef7a
8、使用 curl 命令及 Docker Registry 服务 API v2 列出 Registry 中的镜像:
$ curl -v -X GET http://localhost:5000/v2/hello-mine/tags/list* Hostname was NOT found in DNS cache * Trying 127.0.0.1...* Connected to localhost (127.0.0.1) port 5000 (#0)> GET /v2/hello-mine/tags/list HTTP/1.1> User-Agent: curl/7.35.0> Host: localhost:5000> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Type: application/json; charset=utf-8
< Docker-Distribution-Api-Version: registry/2.0
< Date: Sun, 12 Apr 2015 01:29:47 GMT
< Content-Length: 40
页:
[1]