Docker 自建仓库面临一个管理镜像的问题,这里写个简单的程序,当作抛砖引玉


  • pom.xml需要引入的架包,由于jfinal里面有个封装好的http处理函数,方便简单,所以需要个jfinal包,json包用于解析返回的json结果

  1. <dependency>

  2.     <groupId>com.jfinalgroupId>

  3.     <artifactId>jfinalartifactId>

  4.     <version>2.2version>

  5.    dependency>

  6.    <dependency>

  7.     <groupId>com.hynnetgroupId>

  8.     <artifactId>json-libartifactId>

  9.     <version>2.4version>

  10.    dependency>


  • 简单的代码内容


  1. import com.jfinal.kit.HttpKit;

  2. import net.sf.json.JSONArray;

  3. import net.sf.json.JSONObject;

  4. public class Main {

  5.    // get url 没什么特别,模拟请求URL

  6. public static String httget(String url) {

  7. String s = HttpKit.get(url);

  8. return s;

  9. }

  10. public static void main(String[] args) {


  11. // http://10.100.112.243:5000 是自建仓库的地址,现在基于V2版本

  12. String baseUrl = "http://10.100.112.243:5000/v2/";

  13. String catalog = baseUrl + "_catalog";

  14.      

  15.    // 查看所有镜像名称

  16.       JSONObject obj = JSONObject.fromObject(httget(catalog));

  17.        // 根据返回的json串,转换成json数组,方便操作

  18. JSONArray obj_minions = obj.getJSONArray("repositories");

  19.        // 显示所有内容

  20. for (int i = 0; i < obj_minions.size(); i++) {

  21. System.out.println( httget(baseUrl + "/" + obj_minions.get(i) + "/tags/list"));

  22. }

  23. }

  24. }


  • 执行结果

  1. {"name":"apsops/filebeat-kubernetes","tags":["v0.2"]}

  2. {"name":"bobrik/curator","tags":["latest"]}

  3. {"name":"busybox","tags":["latest"]}



上面简单显示了如何调用查看自建仓库内容,也就是实现CURD里面的“C”查看。

其它的实现可以参考下面的接口进行开发,至于界面设计,其实用一个表格就可以实现,这里也不多说。



常用自建接口(参考1)

method path Entity Description
GET /v2/ Base Check that the endpoint implements Docker Registry API V2.
GET /v2//tags/list Tags Fetch the tags under the repository identified by name.
GET /v2//manifests/ Manifest Fetch the manifest identified by nameand referencewhere referencecan be a tag or digest. A HEADrequest can also be issued to this endpoint to obtain resource information without receiving all data.
PUT /v2//manifests/ Manifest Put the manifest identified by nameand referencewhere referencecan be a tag or digest.
DELETE /v2//manifests/ Manifest Delete the manifest identified by nameand reference. Note that a manifest can only be deleted by digest.
GET /v2//blobs/ Blob Retrieve the blob from the registry identified bydigest. A HEADrequest can also be issued to this endpoint to obtain resource information without receiving all data.
DELETE /v2//blobs/ Blob Delete the blob identified by nameand digest
POST /v2//blobs/uploads/ Initiate Blob Upload Initiate a resumable blob upload. If successful, an upload location will be provided to complete the upload. Optionally, if thedigest parameter is present, the request body will be used to complete the upload in a single request.
GET /v2//blobs/uploads/ Blob Upload Retrieve status of upload identified byuuid. The primary purpose of this endpoint is to resolve the current status of a resumable upload.
PATCH /v2//blobs/uploads/ Blob Upload Upload a chunk of data for the specified upload.
PUT /v2//blobs/uploads/ Blob Upload Complete the upload specified by uuid, optionally appending the body as the final chunk.
DELETE /v2//blobs/uploads/ Blob Upload Cancel outstanding upload processes, releasing associated resources. If this is not called, the unfinished uploads will eventually timeout.
GET /v2/_catalog Catalog Retrieve a sorted, json list of repositories available in the registry.


参考1  http://blog.csdn.net/ztsinghua/article/details/51496658