配置适合 v1 及 v2 版本 Registry 的 Nginx
本节介绍了如何使用
此过程使用您在上面最后一个过程中创建的 安装 Docker Compose
1、在你
2、获取 $ sudo wget https://github.com/docker/compose/releases/download/1.1.0/docker-compose-`uname -s`-`uname -m` -O /usr/local/bin/docker-compose
此命令将二进制可执行文件安装到 3、添加可执行权限到二进制文件。 $ sudo chmod +x /usr/local/bin/docker-compose 做一些清理1、移除早先的镜像。 $ docker rmi -f $(docker images -q -a ) 该步骤是一个内部管理步骤。这可以防止你在这个例子里错误地选取了旧的镜像。
2、编辑
如果沿用了前面例子里的东西,你就会有一个 3、保存变更并关闭文件。 配置 SSL1、进入 distribution/contrib/compose/nginx 目录。 该目录包含了 Nginx 及 Registry 的配置文件。 2、使用 SSL 生成自签名证书。 $ openssl req \ -newkey rsa:2048 -nodes -keyout domain.key \ -x509 -days 365 -out domain.crt 此命令将提示你回答一些问题,供证书创建使用。
3、编辑 COPY domain.crt /etc/nginx/domain.crt COPY domain.key /etc/nginx/domain.key 当你全部搞完的时候,这个文件看上去像下面。 FROM nginx:1.7 COPY nginx.conf /etc/nginx/nginx.conf COPY registry.conf /etc/nginx/conf.d/registry.conf COPY docker-registry.conf /etc/nginx/docker-registry.conf COPY docker-registry-v2.conf /etc/nginx/docker-registry-v2.conf COPY domain.crt /etc/nginx/domain.crt COPY domain.key /etc/nginx/domain.key
4、保存并关闭
5、编辑 ssl on; ssl_certificate /etc/nginx/domain.crt; ssl_certificate_key /etc/nginx/domain.key;
这是一个
6、保存并关闭 构建并运行
1、进到
此目录包含单一个 nginx: build: "nginx" ports: - "5000:5000" links: - registryv1:registryv1 - registryv2:registryv2 registryv1: image: registry ports: - "5000" registryv2: build: "../../" ports: - "5000"
此配置按 2、获取 Registry 1.0 镜像。 $ docker pull registry:0.9.1 Compose 的配置是在本地寻找此镜像。如果你不做这步,那后面的步骤会失败。
3、构建 $ docker-compose build registryv1 uses an image, skipping Building registryv2... Step 0 : FROM golang:1.4 ... Removing intermediate container 9f5f5068c3f3 Step 4 : COPY docker-registry-v2.conf /etc/nginx/docker-registry-v2.conf ---> 74acc70fa106 Removing intermediate container edb84c2b40cb Successfully built 74acc70fa106 此命令将输出其执行过程,直到运行结束。 4、启动使用了 Compose 的配置。 $ docker-compose up Recreating compose_registryv1_1... Recreating compose_registryv2_1... Recreating compose_nginx_1... Attaching to compose_registryv1_1, compose_registryv2_1, compose_nginx_1 ... 5、在另一个终端,显示运行中的配置。 $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a81ad2557702 compose_nginx:latest "nginx -g 'daemon of 8 minutes ago Up 8 minutes 80/tcp, 443/tcp, 0.0.0.0:5000->5000/tcp compose_nginx_1 0618437450dd compose_registryv2:latest "registry cmd/regist 8 minutes ago Up 8 minutes 0.0.0.0:32777->5000/tcp compose_registryv2_1 aa82b1ed8e61 registry:latest "docker-registry" 8 minutes ago Up 8 minutes 0.0.0.0:32776->5000/tcp compose_registryv1_1 浏览一下
1、检查一下你 $ curl -v https://localhost:5000 * Rebuilt URL to: https://localhost:5000/ * Hostname was NOT found in DNS cache * Trying 127.0.0.1... * Connected to localhost (127.0.0.1) port 5000 (#0) * successfully set certificate verify locations: * CAfile: none CApath: /etc/ssl/certs * SSLv3, TLS handshake, Client hello (1): * SSLv3, TLS handshake, Server hello (2): * SSLv3, TLS handshake, CERT (11): * SSLv3, TLS alert, Server hello (2): * SSL certificate problem: self signed certificate * Closing connection 0 curl: (60) SSL certificate problem: self signed certificate More details here: http://curl.haxx.se/docs/sslcerts.html
2、标记 $ docker tag registry:latest localhost:5000/registry_one:latest
3、将其推送到 $ docker push localhost:5000/registry_one:latest
如果你在使用 1.6 版本的 Docker 客户端,这将推送镜像到
4、使用 $ curl -v -X GET http://localhost:32777/v2/registry1/tags/list * Hostname was NOT found in DNS cache * Trying 127.0.0.1... * Connected to localhost (127.0.0.1) port 32777 (#0) > GET /v2/registry1/tags/list HTTP/1.1 > User-Agent: curl/7.36.0 > Host: localhost:32777 > Accept: */* > < HTTP/1.1 200 OK < Content-Type: application/json; charset=utf-8 < Docker-Distribution-Api-Version: registry/2.0 < Date: Tue, 14 Apr 2015 22:34:13 GMT < Content-Length: 39 < {"name":"registry1","tags":["latest"]} * Connection #0 to host localhost left intact
本例参照引用了分配给 2.0 Registry 服务的特定端口。早些时候,在使用 (责任编辑:IT) |