harbor的部署比較簡(jiǎn)單,基本就是一個(gè)命令,這里不做介紹,官網(wǎng)也比較詳細(xì)。
harbor2.x默認(rèn)情況下,配置好hostname,部署好以后就可以通過hostname的域名或者IP訪問。
但是有時(shí)候,服務(wù)器前端還有一層代理服務(wù)器,比如nginx或slb等,這個(gè)時(shí)候按照默認(rèn)的harbor配置,代理以后就無法正常訪問。
只需要修改harbor.yml,把https相關(guān)的注釋,(如果沒有注釋,http會(huì)自動(dòng)重定向到https,導(dǎo)致多次重定向)然后添加:
external_url: https://docker.amd5.cn # (或者external_url: http://docker.amd5.cn),如果這里是https,nginx代理就需要配置ssl。
修改配置以后不能安裝notary,即不能使用--with-notary參數(shù)。然后執(zhí)行:
#prepare - -with-clair - -with-chartmuseum
#docker-compose up -d
啟動(dòng)以后,配置好nginx或者slb代理就可以正常訪問了。
如果docker push報(bào)錯(cuò):unauthorized: unauthorized to access repository(unauthorized: authentication required) 或者日志里面報(bào)錯(cuò):unknown blob,編輯 common/config/nginx/nginx.conf , 注釋掉所有的 proxy_set_header X-Forwarded-Proto $scheme; 重啟即可。(執(zhí)行prepare后需要再次修改)
如果docker push報(bào)錯(cuò):received unexpected HTTP status: 502 Bad Gateway (這種情況我是用了阿里云SLB出現(xiàn)的,nginx反向代理的時(shí)候,未出現(xiàn)此問題),主要原因是:
docker login的時(shí)候,回話只進(jìn)行了一次,并且都走了https協(xié)議,所以沒有出現(xiàn)問題。
而docker push操作,分為2步:
驗(yàn)證: 和login類似,多了步去查你的權(quán)限。
push: 這里恰恰出了問題,因?yàn)樗吡薶ttp的協(xié)議,相關(guān)規(guī)則的文件:(https://github.com/docker/distribution/blob/master/registry/api/v2/urls.go)
而重新走了http的內(nèi)容,會(huì)被認(rèn)為是401的,所以會(huì)出了上邊的報(bào)錯(cuò)。
證書需要購買或者自己生成,下面是nginx配置:
upstream harbor { server 192.168.1.222:80 weight=1; } server { listen 80; listen 443 ssl; server_name docker.amd5.cn; ssl_certificate /etc/nginx/vhost/ssl/www.zhongjima.net.pem; ssl_certificate_key /etc/nginx/vhost/ssl/www.zhongjima.net.key; ssl_session_timeout 5m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; location / { proxy_pass http://harbor; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 20m; client_body_buffer_size 128k; proxy_connect_timeout 90; proxy_read_timeout 90; proxy_buffer_size 4k; proxy_buffers 6 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; } }
證書生成,可以參考http://www.zhongjima.net/atang_3162.html 證書生成部分。
其他docker鏡像倉庫部署:
搭建具有認(rèn)證、TLS的docker registry私有倉庫 http://www.zhongjima.net/atang_3828.html
使用Nexus3.x搭建Docker私有倉庫 http://www.zhongjima.net/atang_4286.html