docker push (harbor)

载入镜像

docker load -i images


登陆harbor

#docker login 192.168.100.226:5080


查看本机镜像

[root@Dev253 coturn]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
coturn-custom arm64 f37fc2047dd8 37 hours ago 202MB
coturn-custom amd64 e1feaea138e9 37 hours ago 202MB
localhost:5000/coturn-custom 1.0 638f58c50079 37 hours ago 201MB
coturn-custom 1.0 638f58c50079 37 hours ago 201MB
<none> <none> b05df936665e 42 hours ago 117MB
moby/buildkit buildx-stable-1 2b2263f26d97 11 days ago 240MB
tonistiigi/binfmt latest fb4f8f43716f 6 weeks ago 85.1MB
kingbasev8r3 v1 5dcb76dacef9 2 months ago 375MB
rockylinux 9 60c8e2290c74 2 years ago 193MB
registry 2 26b2eb03618e 2 years ago 25.4MB


为镜像打标签:

e.g:

#docker tag coturn-custom:arm64 192.168.100.226:5080/wisdom/coturn-custom:arm64
#docker tag coturn-custom:amd64 192.168.100.226:5080/wisdom/coturn-custom:amd64

推送镜像:

e.g:

#docker push 192.168.100.226:5080/wisdom/redis-custom:arm64
#docker push 192.168.100.226:5080/wisdom/redis-custom:amd64

為這兩個不同架構的鏡像打上統一的標籤(例如 v1.0)並建立多架構關聯

1. 為不同架構建立統一的 Manifest 標籤
這步會將你剛上傳的兩個獨立鏡像「打包」成一個邏輯上的標籤:
e.g:
#export DOCKER_CLI_EXPERIMENTAL=enabled
#docker manifest create --insecure 192.168.100.226:5080/wisdom/coturn-custom:v1.0 \
    192.168.100.226:5080/wisdom/coturn-custom:arm64 \
    192.168.100.226:5080/wisdom/coturn-custom:amd64

#docker manifest create 192.168.100.226:5080/wisdom/coturn-custom:v1.0 \ 192.168.100.226:5080/wisdom/coturn-custom:arm64 \ 192.168.100.226:5080/wisdom/coturn-custom:amd64 
2. 推送统一標籤到 Harbor
#docker manifest push 192.168.100.226:5080/wisdom/coturn-custom:v1.0
3.执行签名
#[root@Dev253 redis]# cosign sign --key cosign.key --allow-http-registry 192.168.100.226:5080/wisdom/coturn-custom:v1.0
    • 自動識別:別人 docker pull ...:v1.0 時,Docker 會根據他的 CPU 自動抓 arm64 或 amd64,不用再手動選後綴。
    • Harbor 視圖:在 Harbor 介面中,v1.0 會顯示為一個 Multi-architecture 類型的 Artifact。


  • Docker 客戶端在執行 manifest 指令時,無法從你的 HTTP Harbor 獲取必要的元數據(Manifests)。即便你已經 pull 了鏡像,docker manifest 指令在與非 HTTPS 的倉庫交互時,經常會因為安全限制而直接回報 no such manifest

    方案一:開啟 Docker CLI 的實驗性功能 (推薦)

    有時候 Docker 的 manifest 指令在處理不安全倉庫時需要明確開啟實驗性模式。請執行:
    #export DOCKER_CLI_EXPERIMENTAL=enabled
    #docker manifest create --insecure 192.168.100.226:5080/wisdom/coturn-custom:v1.0 \
        192.168.100.226:5080/wisdom/coturn-custom:arm64 \
        192.168.100.226:5080/wisdom/coturn-custom:amd64
    
    注意:加上了 --insecure 參數來允許存取 HTTP 倉庫。

    方案二:直接使用 docker buildx 合併 (最穩定)

    如果你已經有這兩個不同架構的鏡像,使用 buildx imagetools 建立 Manifest 通常比原生的 docker manifest 指令對 HTTP 倉庫的相容性更好:
    #docker buildx imagetools create -t 192.168.100.226:5080/wisdom/coturn-custom:v1.0 \
        192.168.100.226:5080/wisdom/coturn-custom:arm64 \
        192.168.100.226:5080/wisdom/coturn-custom:amd64
    

    推送manifest

    #docker manifest push --insecure 192.168.100.226:5080/wisdom/coturn-custom:v1.0

    执行签名

    [root@Dev253 redis]# /usr/local/bin/cosign sign --key cosign.key --allow-http-registry 192.168.100.226:5080/wisdom/coturn-custom:v1.0

實現鏡像簽名

  • 安裝 Cosign:在本地機器安裝 Cosign CLI
  • 生成密鑰對
    cosign generate-key-pair
    
  • 鏡像
    # 將 <IMAGE> 替換為你的 Harbor 鏡像地址,例如 10.100.10.251:5080/myproject/myimage:v1
    cosign sign --key cosign.key <IMAGE>
    
    下載二進制檔
    執行以下指令直接安裝最新版的 cosign [1]
    # 1. 下載對應 Linux x86_64 的二進制檔
    curl -O -L "https://github.com/sigstore/cosign/releases/latest/download/cosign-linux-amd64"
    
    # 2. 移動到系統路徑並賦予執行權限
    sudo mv cosign-linux-amd64 /usr/local/bin/cosign
    sudo chmod +x /usr/local/bin/cosign
    
    # 3. 檢查版本確認安裝成功
    cosign version
    
    
    cosign 不能對 .tar 檔案進行簽名,它必須針對已經推送到倉庫(Registry)中的 鏡像標籤(Image Tag)摘要(Digest) 進行操作。
    簽名的數據(簽名文件)會作為一個獨立的 Artifact 存儲在 Harbor 中,與你的鏡像關聯。

    正確的簽名步驟

    執行鏡像簽名

    請分別對你的兩個架構鏡像執行簽名(記得將關鍵字替換為你的實際文件名):
    1、簽名 AMD64 鏡像:
    /usr/local/bin/cosign sign --key cosign.key --allow-http-registry 192.168.100.226:5080/wisdom/coturn-custom:amd64
    
    2、簽名 ARM64 鏡像:
    /usr/local/bin/cosign sign --key cosign.key --allow-http-registry 192.168.100.226:5080/wisdom/coturn-custom:arm64
    

    基础签名方式:

    1. 簽名 amd64 版本

    /usr/local/bin/cosign sign --key cosign.key 192.168.100.226:5080/wisdom/coturn-custom:amd64
    
    2. 簽名 arm64 版本
    /usr/local/bin/cosign sign --key cosign.key 192.168.100.226:5080/wisdom/coturn-custom:arm64
    

    注意事項
    1. 認證問題:執行 cosign sign 之前,請確保你已經執行過 docker login 192.168.100.226:5080,因為 Cosign 會複用 Docker 的認證資訊來上傳簽名。
    2. HTTP/HTTPS 問題
      由於你的 Harbor 使用的是 HTTP(5080 端口),Cosign 預設會強制使用 HTTPS。如果報錯,請在指令前加上 COSIGN_EXPERIMENTAL=1(針對舊版)或在較新版本中使用 --allow-http-registry 參數:
      bash
      /usr/local/bin/cosign sign --key cosign.key --allow-http-registry 192.168.100.226:5080/wisdom/coturn-custom:amd64
      
      請謹慎使用程式碼。
    3. 檢查結果:簽名完成後,回到 Harbor 網頁界面重新整理,你應該會看到 amd64arm64 標籤旁邊出現了 Signed 的標誌。

    追求「完美」,想消除警告(選用):

    # 1. 獲取 Digest
    docker inspect --format='{{index .RepoDigests 0}}' 192.168.100.226:5080/wisdom/coturn-custom:amd64
    
    # 2. 使用輸出的完整地址(包含 @sha256:xxx)進行簽名
    /usr/local/bin/cosign sign --key cosign.key --allow-http-registry <剛才輸出的完整地址>
    

版权声明:
作者:yxbinghe
链接:https://www.zhanhao.ch/?p=675
来源:ice.99
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>