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.參考資料

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