基于Harbor如何搭建Docker私有鏡像倉庫

這篇文章主要講解了“基于Harbor如何搭建Docker私有鏡像倉庫”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“基于Harbor如何搭建Docker私有鏡像倉庫”吧!

創(chuàng)新互聯(lián)專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于網(wǎng)站建設(shè)、成都做網(wǎng)站、撫遠(yuǎn)網(wǎng)絡(luò)推廣、成都小程序開發(fā)、撫遠(yuǎn)網(wǎng)絡(luò)營銷、撫遠(yuǎn)企業(yè)策劃、撫遠(yuǎn)品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運營等,從售前售中售后,我們都將竭誠為您服務(wù),您的肯定,是我們最大的嘉獎;創(chuàng)新互聯(lián)為所有大學(xué)生創(chuàng)業(yè)者提供撫遠(yuǎn)建站搭建服務(wù),24小時服務(wù)熱線:13518219792,官方網(wǎng)址:muchs.cn

什么是 harbor?

第一次使用這個的時候是剛進(jìn)公司處理的第一個任務(wù)的時候,發(fā)現(xiàn) harbor 就是一個用于存儲和分發(fā) docker 鏡像的企業(yè)級registry 服務(wù)器。

網(wǎng)上找到一個 harbor 的架構(gòu)圖:

基于Harbor如何搭建Docker私有鏡像倉庫

harbor 是 vmware 公司開源的企業(yè)級 dockerregistry 項目,項目地址為 https://github.com/vmware/harbor。其目標(biāo)是幫助用戶迅速搭建一個企業(yè)級的 docker registry 服務(wù)。它以 docker 公司開源的 registry 為基礎(chǔ),提供了管理ui,基于角色的訪問控制(role based access control),ad/ldap集成、以及審計日志(auditlogging) 等企業(yè)用戶需求的功能,同時還原生支持中文。harbor 的每個組件都是以 docker 容器的形式構(gòu)建的,使用 docker compose 來對它進(jìn)行部署。

環(huán)境準(zhǔn)備

1、自己在騰訊云買的服務(wù)器(centos7.3)

2、docker 版本:17.05.0-ce

3、docker-compose:1.17.1

4、harbor:1.1.2

安裝 docker

因為系統(tǒng)是 centos 7.3 ,內(nèi)核啥的都已經(jīng)是 3.10,所以不用擔(dān)心內(nèi)核升級的問題,一些操作啥的在 7.x 上操作也很方便。

yum update               //系統(tǒng)版本更新
vim /etc/yum.repos.d/docker.repo    //添加以下內(nèi)容

[dockerrepo]
name=docker repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
//下面安裝 docker 引擎
yum install docker-engine -y
//安裝docker引擎,此步也可作為更新docker版本的操作:先#systemctl stop docker 停止docker服務(wù),再#yum install docker-engine 更新docker版本
systemctl enable docker.service
systemctl start  docker       //啟動docker守護(hù)進(jìn)程
docker info              //查看docker運行情況
docker -v              //查看版本信息

修改 docker 配置文件 /etc/default/docker 如下:

復(fù)制代碼 代碼如下:


docker_opts="--registry-mirror=http://aad0405c.m.daocloud.io" //換成國內(nèi)的鏡像加速源,不然拉取鏡像簡直龜速,不想在吐槽了

使用 service docker restart 重啟 docker 服務(wù)即可。

或者用官方提供的方式:

復(fù)制代碼 代碼如下:

curl -ssl  | sh -s ]

安裝 docker-compose

如果是想直接命令安裝也行,

下載指定版本的docker-compose

[code]
sudo curl -l  -s`-`uname -m` -o /usr/local/bin/docker-compose

對二進(jìn)制文件賦可執(zhí)行權(quán)限

chmod +x /usr/local/bin/docker-compose

測試下docker-compose是否安裝成功

docker-compose --version

出現(xiàn)如下

docker-compose version 1.17.1, build 6d101fb

但是,這種方法簡直龜速,幸好還有種方法,

見這里:

這種需要通過 python 的 pip 安裝

安裝 pip

wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-1.4.2.tar.gz
tar -vxf setuptools-1.4.2.tar.gz
cd setuptools-1.4.2
python2.7 setup.py install    //因為服務(wù)器自帶 python 2.7
easy_install-2.7 pip

安裝 docker compose

pip install docker-compose
docker-compose --version  //測試安裝是否成功

安裝 harbor

wget https://github.com/vmware/harbor/releases/download/v1.1.2/harbor-offline-installer-v1.1.2.tgz
#離線安裝包,也是龜速,把這個下載鏈接用迅雷下載,速度卻賊快,嘿嘿,然后再傳到服務(wù)器上去,整個過程快很多!
tar -zxvf harbor-offline-installer-v1.1.2.tgz

解壓縮之后,進(jìn)入目錄下會看到 harbor.cfg 文件,該文件就是 harbor 的配置文件。

## configuration file of harbor
# hostname設(shè)置訪問地址,可以使用ip、域名,不可以設(shè)置為127.0.0.1或localhost
hostname = 115.159.227.249  #這里我先配置我的服務(wù)器ip地址
# 訪問協(xié)議,默認(rèn)是http,也可以設(shè)置https,如果設(shè)置https,則nginx ssl需要設(shè)置on
ui_url_protocol = http
# MySQL數(shù)據(jù)庫root用戶默認(rèn)密碼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 = sample_admin@mydomain.com
email_password = abc
email_from = admin <sample_admin@mydomain.com>
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登錄的密碼,默認(rèn)是harbor12345
harbor_admin_password = harbor12345
# 認(rèn)證方式,這里支持多種認(rèn)證方式,如ladp、本次存儲、數(shù)據(jù)庫認(rèn)證。默認(rèn)是db_auth,mysql數(shù)據(jù)庫認(rèn)證
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有效時間,默認(rèn)30分鐘
token_expiration = 30
# 用戶創(chuàng)建項目權(quán)限控制,默認(rèn)是everyone(所有人),也可以設(shè)置為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************************

啟動 harbor,修改完配置文件后,在的當(dāng)前目錄執(zhí)行./install.sh,harbor服務(wù)就會根據(jù)當(dāng)期目錄下的docker-compose.yml開始下載依賴的鏡像,檢測并按照順序依次啟動各個服務(wù)。

啟動完成后,我們訪問剛設(shè)置的 hostname 即可,http://115.159.227.249/,默認(rèn)是80端口,如果端口占用,我們可以去修改docker-compose.yml文件中,對應(yīng)服務(wù)的端口映射。

基于Harbor如何搭建Docker私有鏡像倉庫

登錄 web harbor , 輸入用戶名 admin,默認(rèn)密碼(或已修改密碼)登錄系統(tǒng)。

基于Harbor如何搭建Docker私有鏡像倉庫

我們可以看到系統(tǒng)各個模塊如下:

項目:新增/刪除項目,查看鏡像倉庫,給項目添加成員、查看操作日志、復(fù)制項目等

日志:倉庫各個鏡像create、push、pull等操作日志

系統(tǒng)管理

  1. 用戶管理:新增/刪除用戶、設(shè)置管理員等

  2. 復(fù)制管理:新增/刪除從庫目標(biāo)、新建/刪除/啟停復(fù)制規(guī)則等

  3. 配置管理:認(rèn)證模式、復(fù)制、郵箱設(shè)置、系統(tǒng)設(shè)置等

其他設(shè)置

  1. 用戶設(shè)置:修改用戶名、郵箱、名稱信息

  2. 修改密碼:修改用戶密碼

注意:非系統(tǒng)管理員用戶登錄,只能看到有權(quán)限的項目和日志,其他模塊不可見。

我們要嘗試下能不能把自己 docker 里面的鏡像 push 到 harbor 的 library 里來(默認(rèn)這個 library 項目是公開的,所有人都可以有讀的權(quán)限,都不需要 docker login 進(jìn)來,就可以拉取里面的鏡像)。

注意:

為了后面留坑,我這里先 在自己的 docker.service 中添加倉庫:(這是個坑,建議你先按照我說的做,不然下面可能會一直登錄不上)

vim /usr/lib/systemd/system/docker.service
#里面的這行修改為:(其實就是添加 --insecure-registry 115.159.227.249 )
execstart=/usr/bin/dockerd --insecure-registry 115.159.227.249

添加完了后重新啟動 docker:

systemctl daemon-reload && systemctl enable docker && systemctl start docker

啟動 docker 服務(wù):

service docker start

登錄:(為了測試下能否登錄成功)

admin登錄
$ docker login 115.159.227.249
username: admin
password:
login succeeded

打 tag 并 push

docker tag ubuntu:15.10 115.159.227.249/library/ubuntu:15.10    //給我的鏡像打個 tag

docker push 115.159.227.249/library/ubuntu

the push refers to a repository [115.159.227.249/library/ubuntu]
98d59071f692: pushed
af288f00b8a7: pushed
4b955941a4d0: pushed
f121afdbbd5d: pushed
15.10: digest: sha256:ec89c4a90f45f5e103860191890f48d8379e0504a2881ff706aef0768dc0321b size: 1150

上傳完畢后,登錄web harbor,選擇項目 library,就可以看到我剛 push 的鏡像了。

基于Harbor如何搭建Docker私有鏡像倉庫

感謝各位的閱讀,以上就是“基于Harbor如何搭建Docker私有鏡像倉庫”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對基于Harbor如何搭建Docker私有鏡像倉庫這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識點的文章,歡迎關(guān)注!

網(wǎng)站欄目:基于Harbor如何搭建Docker私有鏡像倉庫
本文網(wǎng)址:http://muchs.cn/article26/ijosjg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設(shè)、手機(jī)網(wǎng)站建設(shè)、響應(yīng)式網(wǎng)站、云服務(wù)器、網(wǎng)站內(nèi)鏈、微信小程序

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都做網(wǎng)站