如何建立私人的 docker registry 架設教學 (二)


Docker Registry 主機架好了,但要怎麼查詢你需要的 Docker Image 或 Tag 號呢?

  • 使用 Restful API 指令進行查詢
  • 架設一台 Docker Web UI

使用 Restful API 指令進行查詢

Docker Registry 有提供 Restful API 來進行查詢 Docker Registry 資料

進行 Docker Images 查詢,使用 curl -X GET http://docker-registry.com.cc:5000/v2/_catalog

[root@nginx ~]# curl -X GET http://docker-registry.com.cc:5000/v2/_catalog
{"repositories":["php72-base","nginx"]}

進行 Docker Image Tags 查詢,使用 curl -X GET http://docker-registry.com.cc:5000/v2/php72-base/tags/list

[root@nginx ~]# curl -X GET http://docker-registry.com.cc:5000/v2/php72-base/tags/list
{"name":"php72-base","tags":["0.0.3","0.0.4","latest"]}

進行 Docker Image Tags 詳細資料查詢,使用 curl -X GET http://docker-registry.com.cc:5000/v2/php72-base/manifests/0.0.3

[root@nginx ~]# curl -X GET http://docker-registry.com.cc:5000/v2/php72-base/manifests/0.0.3
{
   "schemaVersion": 1,
   "name": "php72-base",
   "tag": "0.0.3",
   "architecture": "amd64",
   "fsLayers": [
      {
         "blobSum": "sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4"
      },
      {
         "blobSum": "sha256:a41ff91bd26b38d739060f063b525bd6446357dfd31a8f21927a304b3a289bf0"
      },
      {
         "blobSum": "sha256:d03d00a22c3844cdf2ed6c6fa3b157d46fab31a0b35a2e386038a7b8fb4c77e9"
      }
   ],
   "history": [
      {
         "v1Compatibility": "{\"architecture\":\"amd64\",\"author\":\"conrad\\u003cconrad@netwcom.com\\u003e\",\"config\":{\"Hostname\":\"\",\"Domainname\":\"\",\"User\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":[\"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\",\"LANG=en_US.UTF-8\",\"LANGUAGE=en_US:en\",\"LC_ALL=en_US.UTF-8\"],\"Cmd\":null,\"ArgsEscaped\":true,\"Image\":\"sha256:1af317e30968dea6d77fd5c00d9f79779920bf771c28991619cb57c17d892255\",\"Volumes\":null,\"WorkingDir\":\"\",\"Entrypoint\":[\"/usr/sbin/init\"],\"OnBuild\":null,\"Labels\":{\"build-date\":\"20170911\",\"license\":\"GPLv2\",\"name\":\"CentOS Base Image\",\"vendor\":\"CentOS\"}},\"container\":\"55132dab5d235f14cec21065aa62bed44241eaa209e911f6b43a58bb19bfabe2\",\"container_config\":{\"Hostname\":\"55132dab5d23\",\"Domainname\":\"\",\"User\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":[\"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\",\"LANG=en_US.UTF-8\",\"LANGUAGE=en_US:en\",\"LC_ALL=en_US.UTF-8\"],\"Cmd\":[\"/bin/sh\",\"-c\",\"#(nop) \",\"ENTRYPOINT [\\\"/usr/sbin/init\\\"]\"],\"ArgsEscaped\":true,\"Image\":\"sha256:1af317e30968dea6d77fd5c00d9f79779920bf771c28991619cb57c17d892255\",\"Volumes\":null,\"WorkingDir\":\"\",\"Entrypoint\":[\"/usr/sbin/init\"],\"OnBuild\":null,\"Labels\":{\"build-date\":\"20170911\",\"license\":\"GPLv2\",\"name\":\"CentOS Base Image\",\"vendor\":\"CentOS\"}},\"created\":\"2019-07-30T07:47:51.771891821Z\",\"docker_version\":\"18.09.7\",\"id\":\"3d8b91e357acca2b8e58b43b8093890e1383127783ac222cda898462563c1899\",\"os\":\"linux\",\"parent\":\"40b2e398387bc902981cdc7130d55373f4395cd12a36d50ec340cabc7555a7d3\",\"throwaway\":true}"
      },
      //================(略)================

Docker Registry Restful API 的方法如下:

MethodPathEntityDescription
GET/v2/BaseCheck that the endpoint implements Docker Registry API V2.
GET/v2/<name>/tags/listTagsFetch the tags under the repository identified by name.
GET/v2/<name>/manifests/<reference>ManifestFetch the manifest identified by name and reference where reference can be a tag or digest. A HEAD request can also be issued to this endpoint to obtain resource information without receiving all data.
PUT/v2/<name>/manifests/<reference>ManifestPut the manifest identified by name and reference where reference can be a tag or digest.
DELETE/v2/<name>/manifests/<reference>ManifestDelete the manifest identified by name and reference. Note that a manifest can only be deleted by digest.
GET/v2/<name>/blobs/<digest>BlobRetrieve the blob from the registry identified by digest. A HEAD request can also be issued to this endpoint to obtain resource information without receiving all data.
DELETE/v2/<name>/blobs/<digest>BlobDelete the blob identified by name and digest
POST/v2/<name>/blobs/uploads/Initiate Blob UploadInitiate a resumable blob upload. If successful, an upload location will be provided to complete the upload. Optionally, if the digest parameter is present, the request body will be used to complete the upload in a single request.
GET/v2/<name>/blobs/uploads/<uuid>Blob UploadRetrieve status of upload identified by uuid. The primary purpose of this endpoint is to resolve the current status of a resumable upload.
PATCH/v2/<name>/blobs/uploads/<uuid>Blob UploadUpload a chunk of data for the specified upload.
PUT/v2/<name>/blobs/uploads/<uuid>Blob UploadComplete the upload specified by uuid, optionally appending the body as the final chunk.
DELETE/v2/<name>/blobs/uploads/<uuid>Blob UploadCancel outstanding upload processes, releasing associated resources. If this is not called, the unfinished uploads will eventually timeout.
GET/v2/_catalogCatalogRetrieve a sorted, json list of repositories available in the registry.