亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何正確驗證 docker 客戶端 golang 庫到 gcr.io 注冊表?

如何正確驗證 docker 客戶端 golang 庫到 gcr.io 注冊表?

Go
慕容708150 2023-07-26 17:39:08
我需要使用此包庫以編程方式(使用 golang)登錄 gcr.io docker 注冊表https://godoc.org/github.com/docker/docker/client我嘗試過使用它,我可以成功登錄,但是在將圖像推送到我的 gcr.io 項目注冊表時,它說{"errorDetail":{"message":"unauthorized: You don't have the needed permissions to perform this operation, and you may have invalid credentials. To authenticate your request, follow the steps in: https://cloud.google.com/container-registry/docs/advanced-authentication"},"error":"unauthorized: You don't have the needed permissions to perform this operation, and you may have invalid credentials. To authenticate your request, follow the steps in: https://cloud.google.com/container-registry/docs/advanced-authentication"}您可以看一下該CopyImage方法,其中 被option.DestRegistryAuth分配了輸出gcloud auth print-access-token。用戶名設置為“oauth2accesstoken”,因為我遵循了以下說明: https ://cloud.google.com/container-registry/docs/advanced-authentication至于source參數,假設它來自公共注冊表,如 docker.io/library/alpine:3.10,因此我們可以在不配置任何身份驗證令牌的情況下提取它。但是對于dest參數,目前它是我的私人注冊表中的圖像,例如:asia.gcr.io/<gcp-project-id>/alpine:3.10另外,gcloud auth print-access-token在我這樣做之后調用,gcloud auth login并且我已經擁有訪問我的私人 asia.gcr.io 注冊表的完全權限(在存儲桶級別分配)?,F在奇怪的是,我可以在此處描述docker push之后使用命令成功推送它https://cloud.google.com/container-registry/docs/advanced-authentication。docker login有什么建議嗎?
查看完整描述

1 回答

?
喵喵時光機

TA貢獻1846條經驗 獲得超7個贊

事實證明,RegistryAuthtypes.ImagePush 選項中的 arg 需要一個 base64 編碼字符串。

因此,使用此代碼,我可以成功地將本地映像推送到我的私有注冊表。

? ?authConfig := types.AuthConfig{

? ? ? ? Username: "oauth2accesstoken",

? ? ? ? Password: option.DestRegistryAuth,

? ? }

? ? encodedJSON, err := json.Marshal(authConfig)

? ? if err != nil {

? ? ? ? return fmt.Errorf("error when encoding authConfig. err: %v", err)

? ? }


? ? authStr := base64.URLEncoding.EncodeToString(encodedJSON)


? ? rc, err = destClient.DockerClient.ImagePush(ctx, dest, types.ImagePushOptions{

? ? ? ? RegistryAuth: authStr,

? ? })


查看完整回答
反對 回復 2023-07-26
  • 1 回答
  • 0 關注
  • 213 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號