index顧名思義“索引”,index服務主要提供鏡像索引以及用戶認證的功能。當下載一個鏡像的時候,如下圖所示,首先會去index服務上做 認證,然後查找鏡像所在的registry的地址並放回給docker客戶端,最終docker客戶端再從registry下載鏡像,當然在下載過程中 registry會去index校驗客戶端token的合法性。不同鏡像可以保存在不同的registry服務上,其索引信息都放在index服務上。
開源社區docker倉庫的實現,有兩種運行模式
(1)standalone=true:在這種模式下,倉庫自身提供了簡單的index服務,在實現過程中index只是實現了簡單的索引功能,沒有實現用戶認證功能
(2)standalone=false:在這種模式下,需要配置index的服務訪問點,需自行實現index服務
index對外提供的REST API接口如下:
PUT /v1/repositories/(namespace)/(repo_name)/
在docker push的流程中會調用到,其作用是創建一個repository。創建之前會對用戶密碼以及權限進行驗證,如果合法,則最終會返回一個token至docker客戶端
DELETE /v1/repositories/(namespace)/(repo_name)/
刪除一個repository,刪除之前會對用戶密碼以及權限進行驗
PUT /v1/repositories/(namespace)/(repo_name)/images
在docker push流程中會調用到,其作用是更新repository對應的image列表,更新之前會校驗攜帶的token
GET /v1/repositories/(namespace)/(repo_name)/images
在docker pull流程中會調用到,其作用是獲取repository對應的image列表。獲取之前會對用戶密碼以及權限進行驗證
PUT /v1/repositories/(namespace)/(repo_name)/auth
校驗token的合法性
GET /v1/users/
docker login會調用到此接口,用來驗證用戶的合法性
POST /v1/users/
docker login會調用到此接口,可用來創建一個用戶
PUT /v1/users/username/
用來更新用戶信息
各個接口的請求的具體Header、Action、Response,可參考這裡
https://github.com/ekristen/docker-index,采用node js實現,其中實現了一套簡單的用戶管理。
原文:http://openstack.wiaapp.com/?p=1201