1、下載harbor,地址https://github.com/vmware/harbor
2、進入harbor-master/Deploy目錄,修改harbor.cfg文件,主要修改以下信息
2.1、hostname =10.10.10.10 (這個是harbor所在服務器的ip,不能寫127.0.0.1)
2.2、修改郵箱相關信息
3、執行./prepare命令
4.1
Ubuntu: (sudo vi /etc/default/docker)
DOCKER_OPTS="--insecure-registry 10.10.10.10”
4.2 Centos:
修改/usr/lib/systemd/system/docker.service文件
修改一行 ExecStart=/usr/bin/docker daemon -H fd:// --registry-mirror=https://docker.mirrors.ustc.edu.cn --insecure-registry 10.10.10.10”
為什么要修改這個配置文件呢?--insecure-registry代表本地鏡像庫,修改了以上配置文件后需要重啟docker服務,此時docker login時,將連接指定的本地鏡像庫。
如果不修改這個配置文件,則登錄鏡像私服時(docker login 10.10.10.10”)會拋出如下錯誤
Error response from daemon: Get https://10.10.10.10”/v1/users/: dial tcp 10.10.10.10”:443: getsockopt: connection refused
5、重啟docker服務
service docker restart
7、build並啟動
docker-compose up -d
8、從docker hub上下載hello-world鏡像
docker run hello-world
9、給鏡像打標簽,以便上傳到私服,其中library是harbor默認提供的項目
docker tag hello-world 10.10.20.202/library/hello-world
10、上傳鏡像
登錄鏡像私服,執行以下指令,再輸入用戶名和密碼
docker login 10.10.20.202
上傳鏡像
docker push 10.10.20.202/library/hello-world
11、在瀏覽器上訪問10.10.20.202,用戶名:admin,密碼:Harbor12345登錄完成后,點擊library這個項目,即可看到上傳的hello-world
以下附帶harbor的啟動、停止命令
【Build and start Harbor】
$ sudo docker-compose up -d
Creating harbor_log_1
Creating harbor_mysql_1
Creating harbor_registry_1
Creating harbor_ui_1
Creating harbor_proxy_1
【Stop Harbor】
$ sudo docker-compose stop
Stopping harbor_proxy_1 ... done
Stopping harbor_ui_1 ... done
Stopping harbor_registry_1 ... done
Stopping harbor_mysql_1 ... done
Stopping harbor_log_1 ... done
Restart Harbor after stopping
【Start Harbor】
$ sudo docker-compose start
Starting harbor_log_1
Starting harbor_mysql_1
Starting harbor_registry_1
Starting harbor_ui_1
Starting harbor_proxy_1
Remove Harbor's containers while keeping the image data and Harbor's database files on the file system:
【刪除Harbor】
$ sudo docker-compose rm
Going to remove harbor_proxy_1, harbor_ui_1, harbor_registry_1, harbor_mysql_1, harbor_log_1
Are you sure? [yN] y
Removing harbor_proxy_1 ... done
Removing harbor_ui_1 ... done
Removing harbor_registry_1 ... done
Removing harbor_mysql_1 ... done
Remove Harbor's database and image data (for a clean re-installation):
$ rm -rf /data/database
$ rm -rf /data/registry
對接LDAP認證
Harbor支持兩種認證方式,默認為本地存儲,即賬號信息存儲在mysql下,上文已經具體介紹。接下來介紹另外一 種認證方式LDAP,只需要修改配置文件即可。需要提供ldap url以及ldap basedn參數,並且設置auth_mode為ldap_auth。
快速部署LDAP服務
為了測試方便,我們使用Docker啟動一個LDAP服務器,啟動腳本如下:
!/bin/bash
NAME=ldap_server
docker rm -f $NAME 2>/dev/null
docker run --env LDAP_ORGANISATION="Unitedstack Inc." \
--env LDAP_DOMAIN="ustack.com" \
--env LDAP_ADMIN_PASSWORD="admin_password" \
-v pwd
/containers/openldap/data:/var/lib/ldap \
-v pwd
/containers/openldap/slapd.d:/etc/ldap/slapd.d \
--detach --name $NAME osixia/openldap:1.1.2
創建新用戶,首先需要定義ldif文件,new_user.ldif:
dn: uid=test,dc=ustack,dc=com
uid: test
cn: test
sn: 3
objectClass: top
objectClass: posixAccount
objectClass: inetOrgPerson
loginShell: /bin/bash
homeDirectory: /home/test
uidNumber: 1001
gidNumber: 1001
userPassword: 1q2w3e4r
mail: test@example.com
gecos: test
通過以下腳本創建新用戶,其中ldap_server為LDAP服務容器名稱。
docker cp new_user.ldif ldap_server:/
docker exec ldap_server ldapadd -x \
-D "cn=admin,dc=ustack,dc=com" \
-w admin_password \
-f /new_user.ldif -ZZ
查看用戶是否創建成功:
docker exec ldap_server ldapsearch -x -h localhost \
-b dc=ustack,dc=com -D "cn=admin,dc=ustack,dc=com" \
-w admin_password
檢查test用戶是否存在,若存在,則說明創建成功,否則需要使用docker logs查看日志。
配置Harbor使用LDAP認證
修改harbor.cfg文件關於LDAP配置項,如下:
auth_mode = ldap_auth
ldap_url = ldap://10.10.20.202
ldap_basedn = uid=%s,dc=ustack,dc=com
然后重新部署Harbor:
./prepare
docker-compose stop
docker-compose rm -f
docker-compose up -d
測試是否能夠使用test用戶登錄:
docker login -u test -p 1q2w3e4r \
-e test@example.com 10.10.20.202
參考資料
http://dockone.io/article/1252
Harbor項目:https://github.com/vmware/harbor
官方配置mirror registry文檔:https://github.com/docker/dist ... or.md
Daocloud關於mirror的博客:http://blog.daocloud.io/daocloud-mirror-free/
openLDAP部署:https://github.com/osixia/docker-openldap