码迷,mamicode.com
首页 > 其他好文 > 详细

Docker 自建仓库自行开发管理

时间:2017-01-20 22:29:49      阅读:358      评论:0      收藏:0      [点我收藏+]

标签:docker   开发   自建仓库   

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


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

  1. <dependency>

  2.     <groupId>com.jfinal</groupId>

  3.     <artifactId>jfinal</artifactId>

  4.     <version>2.2</version>

  5.    </dependency>

  6.    <dependency>

  7.     <groupId>com.hynnet</groupId>

  8.     <artifactId>json-lib</artifactId>

  9.     <version>2.4</version>

  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)

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 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/<name>/manifests/<reference>ManifestPut the manifest identified by nameand referencewhere referencecan be a tag or digest.
DELETE/v2/<name>/manifests/<reference>ManifestDelete the manifest identified by nameand reference. Note that a manifest can only be deleted by digest.
GET/v2/<name>/blobs/<digest>BlobRetrieve 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/<name>/blobs/<digest>BlobDelete the blob identified by nameand 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 thedigest 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 byuuid. 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.


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








本文出自 “纳米龙” 博客,请务必保留此出处http://arlen.blog.51cto.com/7175583/1893469

Docker 自建仓库自行开发管理

标签:docker   开发   自建仓库   

原文地址:http://arlen.blog.51cto.com/7175583/1893469

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!