上一篇博文講到了Registry私有倉庫,今天配置一下Harbor倉庫,Harbor呢可以作為公開倉庫,也可以作為私有倉庫,今天就來配置一下Harbor如何實現公開倉庫和私有倉庫。
關於Registry公開倉庫請訪問博文:部署Docker私有倉庫Registry
Registry和Harbor的區別
Registry:是一個私有鏡像倉庫,圖形化支持較差,小型企業使用;
Harbor:支持可視化管理,支持私有倉庫和公有倉庫,支持鏡像的管理控制;
Docker Harbor的優點
VMWare公司的開源鏡像管理解決方案;
支持圖形化管理;
方便訪問和配置;
方便鏡像訪問控制;
支持鏡像負責策略;
審計統計用戶訪問鏡像使用情況;
Docker Harbor依賴的程序
Python;
安裝Docker;
Docker Compose;
一、搭建Harbor倉庫
案例描述:
兩臺CentOS7.4,一臺服務器端,一臺客戶端(測試使用);
兩臺服務器都要安裝Docker服務,我這裡Docker版本是19.03.9版本;
關於Docker容器的安裝請訪問:安裝Docker.v19。03.9版本
1、配置Docker Compose
訪問道雲官網,找到安裝Docker Compose,複製命令到Docker服務器端:道雲
[root@centos01 ~]# curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.5/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose [root@centos01 ~]# chmod +x /usr/local/bin/docker-compose [root@centos01 ~]# docker-compose -v docker-compose version 1.25.5, build 8a1c60f6
2、配置Docker Harbor公開倉庫
1)打開Github官網
打開Github官網搜索harbor,再點擊goharbor/harbor,再點擊“releases”,根據自己所需,下載相應的版本,上傳至服務器(網址如下:https://github.com/goharbor/harbor/releases 也可下載在線安裝的包,我沒試過,可自行嘗試),如下:
2)配置Harbor倉庫
harbor-online-installer-v1.9.1.tgz [root@centos01 ~]# tar zxvf harbor-online-installer-v1.9.1.tgz -C /usr/local/ [root@centos01 ~]# cd /usr/local/harbor/ [root@centos01 harbor]# cp harbor.yml harbor.yml.bak [root@centos01 harbor]# vim harbor.yml 5 hostname: 192.168.100.10 8 http: 10 port: 80 27 harbor_admin_password: Harbor12345 [root@centos01 harbor]# ./install.sh [Step 0]: checking installation environment ... Note: docker version: 19.03.9 Note: docker-compose version: 1.25.5 ……………… Creating harbor-log ... done Creating registryctl ... done Creating redis ... done Creating harbor-portal ... done Creating registry ... done Creating harbor-db ... done Creating harbor-core ... done Creating nginx ... done Creating harbor-jobservice ... done ✔ ----Harbor has been installed and started successfully.---- Now you should be able to visit the admin portal at http://www.benet.com . For more details, please visit https://github.com/goharbor/harbor . [root@centos01 ~]# vim /usr/lib/systemd/system/docker.service 14 ExecStart=/usr/bin/dockerd -H fd:// --cOntainerd=/run/containerd/containerd.sock --insecure-registry 192.168.100.10:80 [root@centos01 harbor]# systemctl daemon-reload [root@centos01 harbor]# systemctl restart docker [root@centos01 harbor]# docker-compose stop [root@centos01 harbor]# docker-compose start [root@centos01 harbor]# netstat -anptu |grep 80 tcp6 0 0 :::80 :::* LISTEN 23473/docker-proxy
3)安裝完成瀏覽器訪問Harbor倉庫
4)創建一個公開倉庫
5)確保image公開倉庫已經創建成功
6)Docker服務器端登錄Harbor倉庫
[root@centos01 ~]# docker login -uadmin -pHarbor12345 192.168.100.10:80 WARNING! Using --password via the CLI is insecure. Use --password-stdin. WARNING! Your password will be stored unencrypted in /root/.docker/config.json. Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-store Login Succeeded [root@centos01 ~]# docker tag tomcat:latest 192.168.100.10:80/image/nginx:nginx [root@centos01 ~]# docker push 192.168.100.10:80/image/nginx:nginx [root@centos01 ~]# docker logout 192.168.100.10:80 Removing login credentials for 192.168.100.10:80
7)Harbor查看鏡像是否上傳成功
3、配置Docker客戶端
1)修改配置文件加載Docker Harbor服務器 [root@centos02 ~]# vim /usr/lib/systemd/system/docker.service ExecStart=/usr/bin/dockerd -H fd:// --cOntainerd=/run/containerd/containerd.sock --insecure-registry 192.168.100.10:80 [root@centos02 ~]# systemctl daemon-reload [root@centos02 ~]# systemctl restart docker [root@centos02 ~]# docker login -uadmin -pHarbor12345 192.168.100.10:80 WARNING! Using --password via the CLI is insecure. Use --password-stdin. WARNING! Your password will be stored unencrypted in /root/.docker/config.json. Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-store Login Succeeded [root@centos02 ~]# docker pull 192.168.100.10:80/image/nginx:nginx [root@centos02 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE 192.168.100.10:80/image/nginx nginx 1b6b1fe7261e 7 days ago 647MB
4、創建Harbor私有倉庫
1)創建私有倉庫
2)創建一個用戶
3)將剛創建的private用戶添加到private私有倉庫中
4)上傳鏡像到Harbor私有倉庫
[root@centos01 ~]# docker tag tomcat:latest 192.168.100.10:80/private/tomcat:tomcat [root@centos01 ~]# docker login -uprivate -pHarbor12345 192.168.100.10:80 WARNING! Using --password via the CLI is insecure. Use --password-stdin. WARNING! Your password will be stored unencrypted in /root/.docker/config.json. Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-store Login Succeeded [root@centos01 ~]# docker push 192.168.100.10:80/private/tomcat:tomcat
5)Harbor查看鏡像是否上傳成功
6)Docker客戶端下載私有倉庫中的鏡像
[root@centos02 ~]# docker login -uprivate -pHarbor12345 192.168.100.10:80 WARNING! Using --password via the CLI is insecure. Use --password-stdin. WARNING! Your password will be stored unencrypted in /root/.docker/config.json. Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-store Login Succeeded [root@centos02 ~]# docker pull 192.168.100.10:80/private/tomcat:tomcat [root@centos02 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE 192.168.100.10:80/image/nginx nginx 1b6b1fe7261e 7 days ago 647MB 192.168.100.10:80/private/tomcat tomcat 1b6b1fe7261e 7 days ago 647MB
7)Harbor支持日誌統計功能
[月球人 ] Docker搭建Harbor公開倉庫的方法示例已經有417次圍觀