Documentation ¶
Overview ¶
Docker Push & Pull
执行 docker push 命令流程:
- docker 向 registry 服务器注册 repository: PUT /v1/repositories/<username>/<repository> -> PUTRepository()
- 参数是 JSON 格式的 <repository> 所有 image 的 id 列表,按照 image 的构建顺序排列。
- 根据 <repository> 的 <tags> 进行循环: 3.1 获取 <image> 的 JSON 文件:GET /v1/images/<image_id>/json -> image.go#GETJSON() 3.2 如果没有此文件或内容返回 404 。 3.3 docker push 认为服务器没有 image 对应的文件,向服务器上传 image 相关文件。 3.3.1 写入 <image> 的 JSON 文件:PUT /v1/images/<image_id>/json -> image.go#PUTJSON() 3.3.2 写入 <image> 的 layer 文件:PUT /v1/images/<image_id>/layer -> image.go#PUTLayer() 3.3.3 写入 <image> 的 checksum 信息:PUT /v1/images/<image_id>/checksum -> image.go#PUTChecksum() 3.4 上传完此 tag 的所有 image 后,向服务器写入 tag 信息:PUT /v1/repositories/(namespace)/(repository)/tags/(tag) -> PUTTag()
- 所有 tags 的 image 上传完成后,向服务器发送所有 images 的校验信息,PUT /v1/repositories/(namespace)/(repo_name)/images -> PUTRepositoryImages()
执行 docker pull 命令流程:
- docker 访问 registry 服务器 repository 的 images 信息:GET /v1/repositories/<username>/<repository>/images -> GetRepositoryImages()
- docker 访问 registry 服务器 repository 的 tags 信息:GET /v1/repositoies/<username>/<repository>/tags -> GetRepositoryTags()
- 根据 <repository> 的 <tags> 中 image 信息进行循环: 3.1 获取 <image> 的 Ancestry 信息:GET /v1/images/<image_id>/ancestry -> GetImageAncestry() 3.2 获取 <image> 的 JSON 数据: GET /v1/images/<image_id>/json -> GetImageJson() 3.3 获取 <image> 的 Layer 文件: GET /v1/images/<image_id/layer -> GetImageLayer()
Docker Registry & Login 执行 docker login 命令流程:
- docker 向 registry 的服务器进行注册执行:POST /v1/users or /v1/users/ -> POSTUsers()
- 创建用户成功返回 201;提交的格式有误、无效的字段等返回 400;已经存在用户了返回 401。
- docker login 收到 401 的状态后,进行登录:GET /v1/users or /v1/users/ -> GETUsers()
- 在登录时,将用户名和密码进行 SetBasicAuth 处理,放到 HEADER 的 Authorization 中,例如:Authorization: Basic ZnNrOmZzaw==
- registry 收到登录的请求,Decode 请求 HEADER 中 Authorization 的部分进行判断。
- 用户名和密码正确返回 200;用户名密码错误返回 401;账户未激活返回 403 错误;其它错误返回 417 (Expectation Failed)
注:
Decode HEADER authorization function named decodeAuth in https://github.com/dotcloud/docker/blob/master/registry/auth.go.
更新 Docker Registry User 的属性:
- 调用 PUT /v1/users/(username)/ 向服务器更新 User 的 Email 和 Password 属性。
- 参数包括 User Email 或 User Password,或两者都包括。
- 更新成功返回 204;传递的参数不是有效的 JSON 格式等错误返回 400;认证失败返回 401;用户没有激活返回 403;没有用户现实 404。
注:
HTTP HEADER authorization decode 验证同 docker login 命令。
Index ¶
- type DroneAPIController
- type ImageAPIController
- func (this *ImageAPIController) GetImageAncestry()
- func (this *ImageAPIController) GetImageJSON()
- func (this *ImageAPIController) GetImageLayer()
- func (this *ImageAPIController) Prepare()
- func (this *ImageAPIController) PutChecksum()
- func (this *ImageAPIController) PutImageJSON()
- func (this *ImageAPIController) PutImageLayer()
- func (i *ImageAPIController) URLMapping()
- type MainController
- type PingAPIController
- type PingResult
- type RepositoryAPIController
- func (this *RepositoryAPIController) GetRepositoryImages()
- func (this *RepositoryAPIController) GetRepositoryTags()
- func (this *RepositoryAPIController) Prepare()
- func (this *RepositoryAPIController) PutRepository()
- func (this *RepositoryAPIController) PutRepositoryImages()
- func (this *RepositoryAPIController) PutTag()
- func (r *RepositoryAPIController) URLMapping()
- type SearchAPIController
- type StaticController
- type StatusAPIController
- type UsersAPIController
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DroneAPIController ¶
type DroneAPIController struct {
beego.Controller
}
func (*DroneAPIController) PostYAML ¶
func (this *DroneAPIController) PostYAML()
func (*DroneAPIController) Prepare ¶
func (this *DroneAPIController) Prepare()
type ImageAPIController ¶
type ImageAPIController struct {
beego.Controller
}
func (*ImageAPIController) GetImageAncestry ¶
func (this *ImageAPIController) GetImageAncestry()
func (*ImageAPIController) GetImageJSON ¶
func (this *ImageAPIController) GetImageJSON()
在 Push 的流程中,docker 客户端会先调用 GET /v1/images/:image_id/json 向服务器检查是否已经存在 JSON 信息。 如果存在了 JSON 信息,docker 客户端就认为是已经存在了 layer 数据,不再向服务器 PUT layer 的 JSON 信息和文件了。 如果不存在 JSON 信息,docker 客户端会先后执行 PUT /v1/images/:image_id/json 和 PUT /v1/images/:image_id/layer 。
func (*ImageAPIController) GetImageLayer ¶
func (this *ImageAPIController) GetImageLayer()
func (*ImageAPIController) Prepare ¶
func (this *ImageAPIController) Prepare()
func (*ImageAPIController) PutChecksum ¶
func (this *ImageAPIController) PutChecksum()
func (*ImageAPIController) PutImageJSON ¶
func (this *ImageAPIController) PutImageJSON()
向数据库写入 Layer 的 JSON 数据
func (*ImageAPIController) PutImageLayer ¶
func (this *ImageAPIController) PutImageLayer()
向本地硬盘写入 Layer 的文件
func (*ImageAPIController) URLMapping ¶
func (i *ImageAPIController) URLMapping()
type MainController ¶
type MainController struct {
beego.Controller
}
func (*MainController) Get ¶
func (this *MainController) Get()
func (*MainController) Prepare ¶
func (this *MainController) Prepare()
type PingAPIController ¶
type PingAPIController struct {
beego.Controller
}
func (*PingAPIController) GetPing ¶
func (this *PingAPIController) GetPing()
func (*PingAPIController) Prepare ¶
func (this *PingAPIController) Prepare()
type PingResult ¶
type PingResult struct {
Result bool
}
type RepositoryAPIController ¶
type RepositoryAPIController struct {
beego.Controller
}
func (*RepositoryAPIController) GetRepositoryImages ¶
func (this *RepositoryAPIController) GetRepositoryImages()
获取一个 Repository 的 Image 信息
func (*RepositoryAPIController) GetRepositoryTags ¶
func (this *RepositoryAPIController) GetRepositoryTags()
func (*RepositoryAPIController) Prepare ¶
func (this *RepositoryAPIController) Prepare()
func (*RepositoryAPIController) PutRepository ¶
func (this *RepositoryAPIController) PutRepository()
func (*RepositoryAPIController) PutRepositoryImages ¶
func (this *RepositoryAPIController) PutRepositoryImages()
Push 命令的最后一步,所有的检查操作,通知操作都在此函数进行。
func (*RepositoryAPIController) PutTag ¶
func (this *RepositoryAPIController) PutTag()
func (*RepositoryAPIController) URLMapping ¶
func (r *RepositoryAPIController) URLMapping()
type SearchAPIController ¶
type SearchAPIController struct {
beego.Controller
}
func (*SearchAPIController) GET ¶
func (this *SearchAPIController) GET()
func (*SearchAPIController) Prepare ¶
func (this *SearchAPIController) Prepare()
type StaticController ¶
type StaticController struct {
beego.Controller
}
func (*StaticController) GetFavicon ¶
func (this *StaticController) GetFavicon()
func (*StaticController) Prepare ¶
func (this *StaticController) Prepare()
func (*StaticController) URLMapping ¶
func (i *StaticController) URLMapping()
type StatusAPIController ¶
type StatusAPIController struct {
beego.Controller
}
func (*StatusAPIController) GET ¶
func (this *StatusAPIController) GET()
func (*StatusAPIController) Prepare ¶
func (this *StatusAPIController) Prepare()
type UsersAPIController ¶
type UsersAPIController struct {
beego.Controller
}
func (*UsersAPIController) GetUsers ¶
func (this *UsersAPIController) GetUsers()
func (*UsersAPIController) PostUsers ¶
func (this *UsersAPIController) PostUsers()
返回 401 错误会让 docker 命令行执行 GET /v1/users 的登录动作。 返回 400 和 403 会在 Docker 客户端抛出错误并终止。 如果支持 docker 命令行创建账户,在创建成功后返回 201 状态吗。
func (*UsersAPIController) Prepare ¶
func (this *UsersAPIController) Prepare()
func (*UsersAPIController) URLMapping ¶
func (u *UsersAPIController) URLMapping()
Click to show internal directories.
Click to hide internal directories.