harbor安裝:參考 https://blog.51cto.com/14306186/2514896
1. 安裝 docker-compose,從github下載下傳安裝包

# 下載下傳
curl -L https://github.com/docker/compose/releases/download/1.25.0/docker-compose-`uname -s`-`uname -m` \
-o /usr/local/bin/docker-compose
# 授權
chmod +x /usr/local/bin/docker-compose
# 檢視是否安裝成功
docker-compose -v
2. 繼續下載下傳 Harbor
可在 Github 搜尋 harbor,選擇需要的版本下載下傳。右鍵複制連接配接位址,使用 wget 指令下載下傳
wget https://storage.googleapis.com/harbor-releases/release-1.7.0/harbor-offline-installer-v1.7.4.tgz
執行解壓步驟:
# 解壓
tar -zxvf harbor-offline-installer-v1.7.4.tgz -C /usr/local
進入harbor目錄,修改 harbor.cfg。隻需修改 hostname 改為本機ip,登入密碼預設 Harbor12345 不用改。
## Configuration file of Harbor
# hostname設定通路位址,可以使用ip、域名,不可以設定為127.0.0.1或localhost
hostname = 115.159.227.249 #這裡我先配置我的伺服器IP位址
# 通路協定,預設是http,也可以設定https,如果設定https,則nginx ssl需要設定on
ui_url_protocol = http
# mysql資料庫root使用者預設密碼root123,實際使用時修改下
db_password = root123
#Maximum number of job workers in job service
max_job_workers = 3
#Determine whether or not to generate certificate for the registry's token.
#If the value is on, the prepare script creates new root cert and private key
#for generating token to access the registry. If the value is off the default key/cert will be used.
#This flag also controls the creation of the notary signer's cert.
customize_crt = on
#The path of cert and key files for nginx, they are applied only the protocol is set to https
ssl_cert = /data/cert/server.crt
ssl_cert_key = /data/cert/server.key
#The path of secretkey storage
secretkey_path = /data
#Admiral's url, comment this attribute, or set its value to NA when Harbor is standalone
admiral_url = NA
#NOTES: The properties between BEGIN INITIAL PROPERTIES and END INITIAL PROPERTIES
#only take effect in the first boot, the subsequent changes of these properties
#should be performed on web ui
#************************BEGIN INITIAL PROPERTIES************************
#Email account settings for sending out password resetting emails.
#Email server uses the given username and password to authenticate on TLS connections to host and act as identity.
#Identity left blank to act as username.
email_identity =
email_server = smtp.mydomain.com
email_server_port = 25
email_username = [email protected]
email_password = abc
email_from = admin <[email protected]>
email_ssl = false
##The initial password of Harbor admin, only works for the first time when Harbor starts.
#It has no effect after the first launch of Harbor.
# 啟動Harbor後,管理者UI登入的密碼,預設是Harbor12345
harbor_admin_password = Harbor12345
# 認證方式,這裡支援多種認證方式,如LADP、本次存儲、資料庫認證。預設是db_auth,mysql資料庫認證
auth_mode = db_auth
#The url for an ldap endpoint.
ldap_url = ldaps://ldap.mydomain.com
#A user's DN who has the permission to search the LDAP/AD server.
#If your LDAP/AD server does not support anonymous search, you should configure this DN and ldap_search_pwd.
#ldap_searchdn = uid=searchuser,ou=people,dc=mydomain,dc=com
#the password of the ldap_searchdn
#ldap_search_pwd = password
#The base DN from which to look up a user in LDAP/AD
ldap_basedn = ou=people,dc=mydomain,dc=com
#Search filter for LDAP/AD, make sure the syntax of the filter is correct.
#ldap_filter = (objectClass=person)
# The attribute used in a search to match a user, it could be uid, cn, email, sAMAccountName or other attributes de
pending on your LDAP/AD ldap_uid = uid
#the scope to search for users, 1-LDAP_SCOPE_BASE, 2-LDAP_SCOPE_ONELEVEL, 3-LDAP_SCOPE_SUBTREE
ldap_scope = 3
#Timeout (in seconds) when connecting to an LDAP Server. The default value (and most reasonable) is 5 seconds.
ldap_timeout = 5
# 是否開啟自注冊
self_registration = on
# Token有效時間,預設30分鐘
token_expiration = 30
# 使用者建立項目權限控制,預設是everyone(所有人),也可以設定為adminonly(隻能管理者)
project_creation_restriction = everyone
#Determine whether the job service should verify the ssl cert when it connects to a remote registry.
#Set this flag to off when the remote registry uses a self-signed or untrusted certificate.
verify_remote_cert = on
#************************END INITIAL PROPERTIES************************
改完成docker配置後,安裝harbor
./install.sh
安裝完成,用浏覽器可以通路了。harbor安裝完成後。ali 是我本地配置的域名,通路端口 80
修改配置,添加配置指向私服倉庫,vim /usr/lib/systemd/system/docker.service
//編寫docker主配置檔案
ExecStart=/usr/bin/dockerd --insecure-registry 128.57.123.96
修改 /etc/docker/daemon.json,添加倉庫配置
{ "insecure-registries":["128.57.123.96"]}
重新加載docker配置,重新開機docker服務。
# 重新開機docker
systemctl daemon-reload
systemctl restart docker
# 注意:docker重新開機完成後,harbor的容器都停了,必須切換到harbor安裝目錄,使用docker-compose工具啟動所有容器
cd /usr/local/harbor/
docker-compose start
# 确認80端口在監聽
netstat -anpt | grep 80
此時,harbor安裝完成。使用密碼 Harbor12345登入
建立項目 test
搭建空白鏡像
# 如果你本地沒有鏡像用,或者鏡像檔案太大,可以自己搭一個空白鏡像,用來測試十分友善。方法如下:
1. 在linux測試目錄,建立一個hello檔案,寫入hello
echo hello > hello
2. 繼續在該測試目錄,建立一個Dockerfile,内容如下:
# FROM scratch:表示建立一個空白鏡像,不依賴任何其他鏡像。此句注釋,不需要拷貝
FROM scratch
ADD hello /
3. 建構鏡像。docker images 發現該鏡像隻有5b大小,用來測試非常合适
docker build -t 128.57.123.96/nbmis/esign/quartz:4.2 .
測試本地 docker 鏡像上傳到 test:docker login 很重要,否則 docker push 時會提示你沒有資源通路權限(這裡我沒有用剛才建立的空白鏡像)
# 1. 本機登入docker私服,登入成功提示:Login Succeeded
docker login -u admin -p Harbor12345 128.57.123.96
# 2. tag給鏡像打新标簽
docker tag goharbor/nginx-photon:v1.7.4 128.57.123.96/test/mynginx:1.0
# 3. 向私服推送鏡像,需登入才有權限
docker push 123.57.128.96/test/mynginx:1.0
# 4. 删除私服鏡像,以下分别套入:私服項目名稱,鏡像名,版本号
curl -u 'admin:Harbor12345' \
-X DELETE \
-H 'Content-Type:application/json' \
'http://128.57.123.96/api/repositories/${projectName}/${appName}/tags/${version}'
登入 harbor,檢視我們建立的test項目,看到鏡像已經上傳成功了
我們再嘗試從私服pull鏡像到本地,首先删除本地鏡像,然後 docker pull 128.57.123.96/test/mynginx:1.0,也能成功!
3. 說明
1) 如果你單個項目的鏡像有很多,執行docker push 128.57.123.96/nbmis/esign/quartz,沒有指定版本号時會把所有版本的鏡像上傳
2)如果你測試時,單個項目不同的版本都是通過 docker tag 複制出來的。那這些鏡像的 IMAGE ID 都會是同一個。此時如果你把這些鏡像都上傳到私服,會有如下問題:
當你從 Harbor 删除其中一個版本時,與該版本鏡像使用同一個 IMAGE ID 的其他版本也會同時被删除。
3)關于使用者和項目:
admin作為系統管理者,能看到所有公開和私有的項目。如果我們建立2個普通使用者 user1, user2。這兩個使用者建立的私有項目,都可以被admin 看到,但這兩個普通使用者隻能看見自己建立的私有項目。