我需要使用此包庫以編程方式(使用 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個贊
事實證明,RegistryAuth
types.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,
? ? })
- 1 回答
- 0 關注
- 213 瀏覽
添加回答
舉報
0/150
提交
取消