1. 程式人生 > >docker基礎:私庫系列:再探Harbor:(8)對映象tag進行操作(for zz)

docker基礎:私庫系列:再探Harbor:(8)對映象tag進行操作(for zz)

harbor使用了docker的registry,docker的registry所提供的api使用起來並不方便,harbor提供了使用/repositories/{repo_name}/tags可以對映象的tag進行重新設定,非常方便,當然也可以通過docker cli方式使用docker tag命令進行修改。但是由於retag的功能是harbor在1.7.0才開始引入的功能,而且目前harbor的1.7.0只是在rc1版本,更多使用之前穩定版本的專案稍微需要走一下曲線救國的路線。

前提準備

harbor環境安裝,詳細參看:

建立project

[[email protected] ~]# cat testproject1.json 
{
  "project_name": "testproject1",
  "metadata": {
    "public": "false"
  }
}
[[email protected] ~]# curl -X POST "http://localhost:32031/api/projects" -H "accept: application/json" -H "Content-Type: application/json" [email protected]
-uadmin:liumiao123 [[email protected] ~]#

在這裡插入圖片描述

推送映象

[[email protected] ~]# docker pull busybox
Using default tag: latest
latest: Pulling from library/busybox
90e01955edcd: Pull complete 
Digest: sha256:2a03a6059f21e150ae84b0973863609494aad70f0a80eaeb64bddd8d92465812
Status: Downloaded newer image for busybox:latest
[
[email protected]
~]# [[email protected] ~]# docker tag busybox:latest 192.168.163.118:32031/testproject1/busybox:v1 [[email protected] ~]# [[email protected] ~]# docker push 192.168.163.118:32031/testproject1/busybox:v1 The push refers to a repository [192.168.163.118:32031/testproject1/busybox] 8a788232037e: Pushed v1: digest: sha256:e2d9acbe92a6def141a9f9f2584468206735308df6a696430e25947882385fb2 size: 527 [[email protected] ~]#
  • 確認推送結果
    在這裡插入圖片描述

  • 確認tag
    在這裡插入圖片描述

修改tag

比如此處需要將v1修改為v2,首先要做如下的事情

[[email protected] ~]# docker tag 192.168.163.118:32031/testproject1/busybox:v1 192.168.163.118:32031/testproject1/busybox:v2
[[email protected] ~]# docker push 192.168.163.118:32031/testproject1/busybox:v2
The push refers to a repository [192.168.163.118:32031/testproject1/busybox]
8a788232037e: Layer already exists 
v2: digest: sha256:e2d9acbe92a6def141a9f9f2584468206735308df6a696430e25947882385fb2 size: 527
[[email protected] ~]#
  • 結果確認
    可以看到v1和v2的tag同時存在,如果這個結果已經能夠滿足要求,即之前的tag存在也不介意,registry和harbor可以使用同樣的方式解決,至此就可以結束了,但是如果希望原有的v1的tag刪除,在1.5.2的harbor的版本就會出現一個小問題。
    在這裡插入圖片描述

一個小問題

Q:選中v1,然後點選 Delete按鈕,結果會是什麼?

在這裡插入圖片描述

  • 結果就是v1和v2都會刪除
    在這裡插入圖片描述
    作為一個普通使用者來說,這個操作的結果需要給予解釋才能夠理解的,當然,使用restapi方式進行刪除在這個版本也有同樣問題。
    在這裡插入圖片描述

所以,最簡單的暫定對應方式就是先刪除在tag+push。當然時候harbor後續的版本自然是更好的選擇之一,但是請注意在retag時,源和目的如果在不同的project,而且相關的許可權又不同的時候,即使是當前的1.7.0的版本也正在改進,畢竟是rc1的版本,但是如果在專案中使用則需多加留意。

參考文章

https://docs.docker.com/registry/spec/api/
http://editor.swagger.io/
https://github.com/goharbor/harbor/blob/master/docs/swagger.yaml