nexus build docker private registry

0. 整体架构说明

nexus作为一个优异的私有仓库平台方便了我们迅速创建管理主流的各种操作, 提高了效率, 本文使用一台虚拟机和宿主机的配合来模拟线上仓库和本地调用的关系, 具体如下:

  • 宿主机: 一台mac
  • 虚拟机: 在宿主机上vmware fusion创建了一台ubuntu 14.04的服务器(192.168.132.148)

最终目标:

  • 在宿主机上可以通过访问虚拟机访问nexus管理站点
  • 在宿主机上可以pull和push进行到虚拟机所创建的仓库

1. 编写docker-compose.yml文件

services:
  registry:
    container_name: nexus3
    environment:
      INSTALL4J_ADD_VM_PARAMS: '-Xmx2g -XX:MaxDirectMemorySize=50g'
    image: sonatype/nexus3
    ports:
    - 80:8081
    - 5000:5000
    restart: always
    volumes:
    - /registry/nexus3data:/nexus-data
version: '2.1'

2. 创建nexus的数据存储目录

sudo mkdir /registry/nexus3data
sudo chown -R 200 /registry/nexus3data

3. setup nexus服务

docker-compose up -d

4. 检验 nexus UI 服务已经启动

docker logs -f nexus3

// 结果如下:
...
-------------------------------------------------
Started Sonatype Nexus OSS 3.14.0-04

-------------------------------------------------

除了上面看日志的方式, 也可以通过访问地址登录验证查看: 浏览器打开: http://{nexus.registry.com}, 默认用户名: admin, 默认密码: admin123

5. 创建一个仓库

group的仓库其实使用多个仓库组合的并且可以使用同一个地址; hosted为真正的私有仓库提供push操作会往这里推送进行; proxy是一个代理可以代理到公开仓库比如docker hub, 一般pull的时候使用, 如果私有库没有镜像那么会从proxy下载并且缓存到私有仓库; 实际情况下发现向一个group仓库push时其实是有问题, 问题请查看NEXUS-9960, 所以尽管提供三类的仓库创建, 实际仅适用hosted仓库, 并设置其http端口为:5000

dproxy

6. 实战检查

一下操作使用时group仓库地址, 包含proxy+hosted, 我们验证group分具有proxy和hosted的功能

  • 拉取私有仓库不存在的镜像(验证proxy)
➜  ~ docker login -u admin -p admin123 192.168.132.148:5000
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
Login Succeeded

➜  ~ docker pull 192.168.132.148:5000/ubuntu
Using default tag: latest
latest: Pulling from ubuntu
473ede7ed136: Pulling fs layer 
c46b5fa4d940: Download complete 
93ae3df89c92: Download complete 
6b1eed27cade: Download complete
  • 推送到镜像到私有仓库(验证) 这里重点
➜  ~ docker tag redis:3.2 192.168.132.148:5000/redis

➜  ~ docker push 192.168.132.148:5000/redis
The push refers to repository [192.168.132.148:5000/redis]
a70b4951f7da: Retrying in 4 seconds 
6484c71204b8: Retrying in 4 seconds 
a339985f1835: Retrying in 4 seconds 
714e32c05337: Retrying in 4 seconds 
d98fb630fb3b: Retrying in 4 seconds 
8b15606a9e3e: Waiting

重点: 向一个group推送镜像其实是不能成功的, 因为nexus不知道到底往那个镜像推送, 所以这个验证是失败的, group也只能提供类似多个镜像只读的操作, 但是group支持推送是一个很好的feature, 目前正在开发中, 详细的情况请查看:Docker Push to docker (group) repository not allowed

7. 问题

  • 503 Service Unavailable

操作: docker login -u admin -p admin123 192.168.132.148:5000

结果: WARNING! Using --password via the CLI is insecure. Use --password-stdin. Error response from daemon: login attempt to http://192.168.132.148:5000/v2/ failed with status: 503 Service Unavailable

原因: 192.168.132.148:5000 地址中的端口没有在container中曝露出来

解决方法: 修改yml文件, 增加ports,例如 - 5000:5000

  • http: server gave HTTP response to HTTPS client

操作: docker login -u admin -p admin123 192.168.132.148:5000

结果: WARNING! Using --password via the CLI is insecure. Use --password-stdin. Error response from daemon: Get https://192.168.132.148:5000/v2/: http: server gave HTTP response to HTTPS client

原因: 安全问题,应该将192.168.132.148:5000加入到客户端--insecure-registries数组中

解决方法: 编辑daemon.json文件增加: insecury-registry: [192.168.132.148:5000], mac有UI的方式, linux可以在/etc/docker/daemon.json中设置

  • error parsing HTTP 404 response body: unexpected end of JSON input: ""

操作: 创建了一个group registry, 并向其push镜像 结果: error parsing HTTP 404 response body: unexpected end of JSON input: "" 原因: 这个设计如此, 因为group不知到底push到多个registry中的哪一个, 详情查看NEXUS-9960 解决方法: 不使用group, 为hosted设置端口5000, push hosted类型仓库

8. 单点登录(SSO)[可选]

9.参考资料

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章