Harbor 是一個企業(yè)級的 Docker Registry墩虹,可以實(shí)現(xiàn) images 的私有存儲和日志統(tǒng)計權(quán)限控制等功能,并支持創(chuàng)建多項目(Harbor 提出的概念)官扣,基于官方 Registry V2 實(shí)現(xiàn)。
目標(biāo):在Ubuntu 16.04上搭建Harbor鏡像倉庫
環(huán)境:
Ubuntu-001:10.140.160.100 作為Harbor鏡像倉庫搭建機(jī)器
Ubuntu-004: 10.140.161.187 作為docker host去測試push pull鏡像
前提條件:已安裝python docker docker-compose
Python應(yīng)該是2.7或更高版本
Docker引擎應(yīng)為1.10或更高版本
Docker Compose需要為1.6.0或更高版本
Harbor 可以通過以下兩種方式之一安裝:(下載地址:https://github.com/vmware/harbor/releases)
在線安裝程序:安裝程序從Docker集線器下載Harbour的映像。因此蠢护,安裝程序的尺寸非常小。
脫機(jī)安裝程序:當(dāng)主機(jī)沒有Internet連接時养涮,請使用此安裝程序葵硕。安裝程序包含預(yù)制圖像,因此其大小較大贯吓。
本次演示離線安裝過程:(我下載了離線安裝包:harbor-offline-installer-v1.5.0.tgz)
1懈凹、解壓harbor-offline-installer-v1.5.0.tgz
tar?xzvf?harbor-offline-installer-v1.5.0.tgz??
2、進(jìn)入harbor宣决,修改harbor.cfg文件
root@Ubuntu-001:~/harbor#?ll??
total?854980??
drwxr-xr-x??4?root?root??????4096?May?17?14:33?./??
drwx------?16?root?root??????4096?May?17?14:33?../??
drwxr-xr-x??4?root?root??????4096?May?17?13:00?common/??
-rw-r--r--??1?root?root??????1185?May??2?23:34?docker-compose.clair.yml??
-rw-r--r--??1?root?root??????1725?May??2?23:34?docker-compose.notary.yml??
-rw-r--r--??1?root?root??????3596?May??2?23:34?docker-compose.yml??
drwxr-xr-x??3?root?root??????4096?May??2?23:34?ha/??
-rw-r--r--??1?root?root??????6685?May?17?12:55?harbor.cfg??
-rw-r--r--??1?root?root?875401338?May??2?23:36?harbor.v1.5.0.tar.gz??
-rwxr-xr-x??1?root?root??????5773?May??2?23:34?install.sh*??
-rw-r--r--??1?root?root?????10771?May??2?23:34?LICENSE??
-rw-r--r--??1?root?root???????482?May??2?23:34?NOTICE??
-rwxr-xr-x??1?root?root?????27379?May??2?23:34?prepare*??
hostname?=?10.140.160.100??
我僅修改了hostname為我的宿主機(jī)ip
3蘸劈、運(yùn)行install.sh腳本
該腳本主要做了以下事情:
(1)檢查docker docker-compose是否安裝及版本
(2)將harbor.v1.5.0.tar.gz解壓并docker load到主機(jī)
(3)環(huán)境準(zhǔn)備
(4)依賴docker-compose.yml文件啟動相關(guān)的容器
root@Ubuntu-001:~/harbor#?./install.sh? ?
[Step?0]:?checking?installation?environment?...??
Note:?docker?version:?17.12.0??
Note:?docker-compose?version:?1.19.0??
[Step?1]:?loading?Harbor?images?...??
52ef9064d2e4:?Loading?layer?[==================================================>]??135.9MB/135.9MB??
c169f7c7a5ff:?Loading?layer?[==================================================>]??154.2MB/154.2MB??
a2194b3a5434:?Loading?layer?[==================================================>]??10.75MB/10.75MB??
f3809b773329:?Loading?layer?[==================================================>]??2.048kB/2.048kB??
bdd2cd4d5394:?Loading?layer?[==================================================>]??48.13kB/48.13kB??
bce61638a813:?Loading?layer?[==================================================>]???10.8MB/10.8MB??
Loaded?image:?vmware/clair-photon:v2.0.1-v1.5.0??
0bf5fb4e60f4:?Loading?layer?[==================================================>]?????95MB/95MB??
9fc876f7ef97:?Loading?layer?[==================================================>]??6.656kB/6.656kB??
9f364ae08e7f:?Loading?layer?[==================================================>]??2.048kB/2.048kB??
d8e3574f27f2:?Loading?layer?[==================================================>]???7.68kB/7.68kB??
Loaded?image:?vmware/postgresql-photon:v1.5.0??
8cb812a02f44:?Loading?layer?[==================================================>]??23.25MB/23.25MB??
826629c35871:?Loading?layer?[==================================================>]??15.36MB/15.36MB??
68fc630fcd08:?Loading?layer?[==================================================>]??15.36MB/15.36MB??
Loaded?image:?vmware/harbor-adminserver:v1.5.0??
fd8233cdfcf0:?Loading?layer?[==================================================>]??23.25MB/23.25MB??
7ab0310b3d9d:?Loading?layer?[==================================================>]???2.56kB/2.56kB??
75609935cf31:?Loading?layer?[==================================================>]???2.56kB/2.56kB??
654b65c0f8ff:?Loading?layer?[==================================================>]??2.048kB/2.048kB??
1da5c77da464:?Loading?layer?[==================================================>]???22.8MB/22.8MB??
5e9191f65a4c:?Loading?layer?[==================================================>]???22.8MB/22.8MB??
Loaded?image:?vmware/registry-photon:v2.6.2-v1.5.0??
Loaded?image:?vmware/photon:1.0??
454c81edbd3b:?Loading?layer?[==================================================>]??135.2MB/135.2MB??
e99db1275091:?Loading?layer?[==================================================>]??395.4MB/395.4MB??
051e4ee23882:?Loading?layer?[==================================================>]??9.216kB/9.216kB??
6cca4437b6f6:?Loading?layer?[==================================================>]??9.216kB/9.216kB??
1d48fc08c8bc:?Loading?layer?[==================================================>]???7.68kB/7.68kB??
0419724fd942:?Loading?layer?[==================================================>]??1.536kB/1.536kB??
543c0c1ee18d:?Loading?layer?[==================================================>]??655.2MB/655.2MB??
4190aa7e89b8:?Loading?layer?[==================================================>]??103.9kB/103.9kB??
Loaded?image:?vmware/harbor-migrator:v1.5.0??
1736beaf11c8:?Loading?layer?[==================================================>]??23.25MB/23.25MB??
3026403c0282:?Loading?layer?[==================================================>]??24.39MB/24.39MB??
1aaf4a794824:?Loading?layer?[==================================================>]??7.168kB/7.168kB??
b427e1a2dd17:?Loading?layer?[==================================================>]??10.56MB/10.56MB??
68906d88fd96:?Loading?layer?[==================================================>]??24.38MB/24.38MB??
Loaded?image:?vmware/harbor-ui:v1.5.0??
cf8fe5c86f4b:?Loading?layer?[==================================================>]??78.26MB/78.26MB??
d15d127e6aa2:?Loading?layer?[==================================================>]??3.072kB/3.072kB??
9d47dbd3d824:?Loading?layer?[==================================================>]???59.9kB/59.9kB??
098c90ca59f4:?Loading?layer?[==================================================>]??61.95kB/61.95kB??
Loaded?image:?vmware/redis-photon:v1.5.0??
71a9f645bc2d:?Loading?layer?[==================================================>]??4.755MB/4.755MB??
Loaded?image:?vmware/nginx-photon:v1.5.0??
c4c015394057:?Loading?layer?[==================================================>]??401.3MB/401.3MB??
f9d78b9c2c97:?Loading?layer?[==================================================>]??9.216kB/9.216kB??
5cf7df688ef1:?Loading?layer?[==================================================>]??9.216kB/9.216kB??
9513efb6efc9:?Loading?layer?[==================================================>]???7.68kB/7.68kB??
52252ffb5fc7:?Loading?layer?[==================================================>]??1.536kB/1.536kB??
Loaded?image:?vmware/mariadb-photon:v1.5.0??
243e37f674cb:?Loading?layer?[==================================================>]??23.25MB/23.25MB??
eb85e1888b13:?Loading?layer?[==================================================>]??10.95MB/10.95MB??
7b86ea27af2e:?Loading?layer?[==================================================>]???17.3MB/17.3MB??
a876e7e90459:?Loading?layer?[==================================================>]??15.87kB/15.87kB??
08c705395182:?Loading?layer?[==================================================>]??3.072kB/3.072kB??
2cb9ada082da:?Loading?layer?[==================================================>]??28.24MB/28.24MB??
Loaded?image:?vmware/notary-signer-photon:v0.5.1-v1.5.0??
b9abce7219b5:?Loading?layer?[==================================================>]??73.15MB/73.15MB??
ee87a4f06084:?Loading?layer?[==================================================>]??3.584kB/3.584kB??
ca647be60b60:?Loading?layer?[==================================================>]??3.072kB/3.072kB??
aeb4260dd4ca:?Loading?layer?[==================================================>]??4.096kB/4.096kB??
4493e8c270cf:?Loading?layer?[==================================================>]??3.584kB/3.584kB??
ce532e45f1e6:?Loading?layer?[==================================================>]??9.728kB/9.728kB??
Loaded?image:?vmware/harbor-log:v1.5.0??
4de8028cebd0:?Loading?layer?[==================================================>]??11.78kB/11.78kB??
b762605dfab6:?Loading?layer?[==================================================>]???2.56kB/2.56kB??
bed1e891c86f:?Loading?layer?[==================================================>]??3.072kB/3.072kB??
Loaded?image:?vmware/harbor-db:v1.5.0??
820ecb80c0fa:?Loading?layer?[==================================================>]??23.25MB/23.25MB??
43ece8a3b461:?Loading?layer?[==================================================>]???20.9MB/20.9MB??
e7ac4a143f8d:?Loading?layer?[==================================================>]???20.9MB/20.9MB??
Loaded?image:?vmware/harbor-jobservice:v1.5.0??
6ae72c7ad4ac:?Loading?layer?[==================================================>]??12.16MB/12.16MB??
1ad34ba80481:?Loading?layer?[==================================================>]???17.3MB/17.3MB??
f6ae3aed7f00:?Loading?layer?[==================================================>]??15.87kB/15.87kB??
1b77c5882538:?Loading?layer?[==================================================>]??3.072kB/3.072kB??
6364681eec7e:?Loading?layer?[==================================================>]??29.46MB/29.46MB??
Loaded?image:?vmware/notary-server-photon:v0.5.1-v1.5.0??
[Step?2]:?preparing?environment?...??
Generated?and?saved?secret?to?file:?/data/secretkey??
Generated?configuration?file:?./common/config/nginx/nginx.conf??
Generated?configuration?file:?./common/config/adminserver/env??
Generated?configuration?file:?./common/config/ui/env??
Generated?configuration?file:?./common/config/registry/config.yml??
Generated?configuration?file:?./common/config/db/env??
Generated?configuration?file:?./common/config/jobservice/env??
Generated?configuration?file:?./common/config/jobservice/config.yml??
Generated?configuration?file:?./common/config/log/logrotate.conf??
Generated?configuration?file:?./common/config/jobservice/config.yml??
Generated?configuration?file:?./common/config/ui/app.conf??
Generated?certificate,?key?file:?./common/config/ui/private_key.pem,?cert?file:?./common/config/registry/root.crt??
The?configuration?files?are?ready,?please?use?docker-compose?to?start?the?service.??
Creating?harbor-log?...?done??
[Step?3]:?checking?existing?instance?of?Harbor?...??
Creating?registry?...?done??
Creating?harbor-ui?...?done??
Creating?network?"harbor_harbor"?with?the?default?driver??
Creating?nginx?...?done??
Creating?harbor-adminserver?...???
Creating?harbor-db?...???
Creating?registry?...???
Creating?redis?...???
Creating?harbor-ui?...???
Creating?nginx?...???
Creating?harbor-jobservice?...???
??----Harbor?has?been?installed?and?started?successfully.----??
Now?you?should?be?able?to?visit?the?admin?portal?at?http://10.140.160.100.???
For?more?details,?please?visit?https://github.com/vmware/harbor?.??
運(yùn)行后的image及啟動的容器
root@Ubuntu-001:~/harbor#?docker?images|grep?vm??
vmware/redis-photon??????????????????????????????????????v1.5.0??????????????7c03076402d9????????2?weeks?ago?????????207MB??
vmware/clair-photon??????????????????????????????????????v2.0.1-v1.5.0???????7ae4e0670a3f????????2?weeks?ago?????????301MB??
vmware/notary-server-photon??????????????????????????????v0.5.1-v1.5.0???????0b2b23300552????????2?weeks?ago?????????211MB??
vmware/notary-signer-photon??????????????????????????????v0.5.1-v1.5.0???????67c41b4a1283????????2?weeks?ago?????????209MB??
vmware/registry-photon???????????????????????????????????v2.6.2-v1.5.0???????3059f44f4b9a????????2?weeks?ago?????????198MB??
vmware/nginx-photon??????????????????????????????????????v1.5.0??????????????e100456182fc????????2?weeks?ago?????????135MB??
vmware/harbor-log????????????????????????????????????????v1.5.0??????????????62bb6b8350d9????????2?weeks?ago?????????200MB??
vmware/harbor-jobservice?????????????????????????????????v1.5.0??????????????aca9fd2e867f????????2?weeks?ago?????????194MB??
vmware/harbor-ui?????????????????????????????????????????v1.5.0??????????????1055166068d0????????2?weeks?ago?????????212MB??
vmware/harbor-adminserver????????????????????????????????v1.5.0??????????????019bc4544829????????2?weeks?ago?????????183MB??
vmware/harbor-db?????????????????????????????????????????v1.5.0??????????????82354dcf564f????????2?weeks?ago?????????526MB??
vmware/mariadb-photon????????????????????????????????????v1.5.0??????????????403e7e656499????????2?weeks?ago?????????526MB??
vmware/postgresql-photon?????????????????????????????????v1.5.0??????????????35c891dea9cf????????2?weeks?ago?????????221MB??
vmware/harbor-migrator???????????????????????????????????v1.5.0??????????????466c57ab0dc3????????2?weeks?ago?????????1.16GB??
vmware/photon????????????????????????????????????????????1.0?????????????????4b481ecbef2a????????3?weeks?ago?????????130MB??
root@Ubuntu-001:~/harbor#?docker?ps|grep?vm??
bf5f9931e56b????????vmware/harbor-jobservice:v1.5.0????????????"/harbor/start.sh"???????2?hours?ago?????????Up?2?hours????????????????????????????????????????????????????????????????????????????????harbor-jobservice??
531cbf68d620????????vmware/nginx-photon:v1.5.0?????????????????"nginx?-g?'daemon?of…"???2?hours?ago?????????Up?2?hours?(healthy)???0.0.0.0:80->80/tcp,?0.0.0.0:443->443/tcp,?0.0.0.0:4443->4443/tcp???nginx??
575f1694fb5e????????vmware/harbor-ui:v1.5.0????????????????????"/harbor/start.sh"???????2?hours?ago?????????Up?2?hours?(healthy)??????????????????????????????????????????????????????????????????????harbor-ui??
e8474e31b25f????????vmware/redis-photon:v1.5.0?????????????????"docker-entrypoint.s…"???2?hours?ago?????????Up?2?hours?????????????6379/tcp???????????????????????????????????????????????????????????redis??
a6d2b313d197????????vmware/harbor-db:v1.5.0????????????????????"/usr/local/bin/dock…"???2?hours?ago?????????Up?2?hours?(healthy)???3306/tcp???????????????????????????????????????????????????????????harbor-db??
226e6ab74032????????vmware/registry-photon:v2.6.2-v1.5.0???????"/entrypoint.sh?serv…"???2?hours?ago?????????Up?2?hours?(healthy)???5000/tcp???????????????????????????????????????????????????????????registry??
bf8557680303????????vmware/harbor-adminserver:v1.5.0???????????"/harbor/start.sh"???????2?hours?ago?????????Up?2?hours?(healthy)??????????????????????????????????????????????????????????????????????harbor-adminserver??
16d5b2ffc0a2????????vmware/harbor-log:v1.5.0???????????????????"/bin/sh?-c?/usr/loc…"???2?hours?ago?????????Up?2?hours?(healthy)???127.0.0.1:1514->10514/tcp??????????????????????????????????????????harbor-log??
root@Ubuntu-001:~/harbor#?docker-compose?ps??
???????Name?????????????????????Command???????????????State????????????????????????????????Ports????????????????????????????????
------------------------------------------------------------------------------------------------------------------------------??
harbor-adminserver???/harbor/start.sh?????????????????Up????????????????????????????????????????????????????????????????????????
harbor-db????????????/usr/local/bin/docker-entr?...???Up??????3306/tcp??????????????????????????????????????????????????????????
harbor-jobservice????/harbor/start.sh?????????????????Up????????????????????????????????????????????????????????????????????????
harbor-log???????????/bin/sh?-c?/usr/local/bin/?...???Up??????127.0.0.1:1514->10514/tcp?????????????????????????????????????????
harbor-ui????????????/harbor/start.sh?????????????????Up????????????????????????????????????????????????????????????????????????
nginx????????????????nginx?-g?daemon?off;?????????????Up??????0.0.0.0:443->443/tcp,?0.0.0.0:4443->4443/tcp,?0.0.0.0:80->80/tcp??
redis????????????????docker-entrypoint.sh?redis?...???Up??????6379/tcp??????????????????????????????????????????????????????????
registry?????????????/entrypoint.sh?serve?/etc/?...???Up??????5000/tcp???
瀏覽器打開:http://10.140.160.100即可進(jìn)入harbor UI管理界面,用戶名/密碼:admin/Harbor12345(在harbor.cfg有說明)
創(chuàng)建自己的項目:
我們勾選了公開尊沸,意味著任何人都可以pull我們這個項目的鏡像威沫。
將Ubuntu-001上的dockersamples/visualizer,重新tag為10.140.160.100/shayu/visualizer洼专,然后push到上述倉庫
由于我們搭建的倉庫僅提供了http服務(wù)棒掠,而docker默認(rèn)采用https,可能出現(xiàn)問題屁商,所以需要在Ubuntu-001 和Ubuntu-004上講倉庫地址登記烟很,然后重啟docker
root@Ubuntu-001:~/harbor#?cat?/etc/docker/daemon.json|python?-m?json.tool??
{??
????"insecure-registries":?[??
????????"10.140.160.100"??
????]??
}??
root@Ubuntu-001:~/harbor#?systemctl?restart?docker.service??
root@Ubuntu-001:~/harbor#?docker?login?10.140.160.100??
Username:?admin??
Password:???
Login?Succeeded??
root@Ubuntu-001:~/harbor#?docker?tag?dockersamples/visualizer?10.140.160.100/shayu/visualizer??
root@Ubuntu-001:~/harbor#?docker?push?10.140.160.100/shayu/visualizer??
The?push?refers?to?repository?[10.140.160.100/shayu/visualizer]??
dc5f5688295b:?Pushed???
165e8d454007:?Pushed???
2c2454e71e24:?Pushed???
4b4a3d056a98:?Pushed???
d04099cd9299:?Pushed???
fb5309439149:?Pushed???
965d16d53496:?Pushed???
56cd83a89d04:?Pushed???
300a6cad969a:?Pushed???
dfd8ee95c7e7:?Pushed???
f7e883283ebc:?Pushed???
0a19bde117a5:?Pushed???
5bef08742407:?Pushed???
latest:?digest:?sha256:32a617fccbd22ff7cb49fe0f6243a87ec5095efa3615b7e9e8dca9d65af515e1?size:?3033??
將Ubuntu-004上的httpd:2.4.29,重新tag為10.140.160.100/shayu/httpd:2.4.29蜡镶,然后push到上述倉庫
root@Ubuntu-004:~/harbor#?docker?login?10.140.160.100??
Username:?admin??
Password:???
Login?Succeeded??
root@Ubuntu-004:~/harbor#?docker?push?10.140.160.100/shayu/httpd:2.4.29??
The?push?refers?to?repository?[10.140.160.100/shayu/httpd]??
e94542d10da9:?Pushed???
e24c9744fa3f:?Pushed???
ab31df24cf72:?Pushed???
7e41cdcec3c2:?Pushed???
f57aec6a98ba:?Pushed???
540a7775e563:?Pushed???
4bcdffd70da2:?Pushed???
2.4.29:?digest:?sha256:f46377c7bc42236b2201a97755afd6b6cb579e2e144883ca1cb6b5a240a3ad91?size:?1780??
root@Ubuntu-004:~/harbor#?docker?pull?10.140.160.100/shayu/visualizer:latest??
latest:?Pulling?from?shayu/visualizer??
6d987f6f4279:?Pull?complete???
96b1d38c63ba:?Pull?complete???
91cf862459ee:?Pull?complete???
39acd566379f:?Pull?complete???
fb8b2bfb7015:?Pull?complete???
755b5704929b:?Pull?complete???
38979178e012:?Pull?complete???
c210aa9a937d:?Pull?complete???
f1c50e8a4329:?Pull?complete???
afdd027f1762:?Pull?complete???
b2353c1e1ec9:?Pull?complete???
9ebae75c595a:?Pull?complete???
1004cdeaed49:?Pull?complete???
Digest:?sha256:32a617fccbd22ff7cb49fe0f6243a87ec5095efa3615b7e9e8dca9d65af515e1??
Status:?Downloaded?newer?image?for?10.140.160.100/shayu/visualizer:latest??
root@Ubuntu-001:~/harbor#?docker?pull?10.140.160.100/shayu/httpd:2.4.29??
2.4.29:?Pulling?from?shayu/httpd??
f49cf87b52c1:?Already?exists???
02ca099fb6cd:?Already?exists???
de7acb18da57:?Already?exists???
770c8edb393d:?Already?exists???
0e252730aeae:?Already?exists???
6288e83d58fa:?Pull?complete???
a91ad03b2178:?Pull?complete???
Digest:?sha256:f46377c7bc42236b2201a97755afd6b6cb579e2e144883ca1cb6b5a240a3ad91??
Status:?Downloaded?newer?image?for?10.140.160.100/shayu/httpd:2.4.29??
當(dāng)然你也可以在UI界面對項目及其鏡像進(jìn)行一些刪除操作: