【问题标题】:Permission issues while docker pushdocker push 时的权限问题
【发布时间】:2019-08-22 03:03:42
【问题描述】:

我正在尝试将我的 docker 映像推送到 google 容器映像注册表,但收到一条错误消息,提示我没有执行此操作所需的权限。

我已经尝试过 gcloud auth configure-docker 但它对我不起作用。

我首先使用以下方法构建图像: docker build -t gcr.io/trynew/hello-world-image:v1 .

然后我尝试附加标签并推送它: docker push gcr.io/trynew/hello-world-image:v1

这是我的输出:

    The push refers to repository [gcr.io/trynew/hello-world-image]

    e62774cdb1c2: Preparing 
    0f6265b750f3: Preparing 
    f82351274ce3: Preparing 
    31a16430afc8: Preparing 
    67298499a3ed: Preparing 
    62d5f39c8fe4: Waiting 
    9f8566ee5135: Waiting 
    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

【问题讨论】:

  • 您找到任何有用的信息了吗?您能否标记有效答案或发布有关问题实际状态的任何信息?
  • 就我而言,我使用的是 docker 的 snap 版本。安装普通版本(目前是 Docker 版本 19.03.3,构建 a872fc2f86)后,问题就消失了。

标签: docker docker-image


【解决方案1】:

谷歌云服务有具体信息如何授予 docker push 的权限,我认为这是你应该看的第一件事,https://cloud.google.com/container-registry/docs/access-control

在检查您是否拥有足够的权限后,您应该使用以下方式进行身份验证:

gcloud auth configure-docker

在此处查看更多信息:https://cloud.google.com/container-registry/docs/pushing-and-pulling

【讨论】:

  • 在您按照所有这些说明进行操作后,您会遇到同样的错误。文档中缺少某些内容。
  • 刚刚在 gcloud docker credential helper 的文档中找到了这个小注释(即上面的命令)...“注意:此命令不适用于通过 Snap 安装的 docker,因为 docker snap 包不目前为凭证助手提供接口。”
【解决方案2】:

为了能够将映像推送到私有注册表,您需要两件事:API 访问范围使用注册表验证您的虚拟机

对于API Access Scopeshttps://cloud.google.com/container-registry/docs/using-with-google-cloud-platform)我们可以在官方文档中阅读:

对于 GKE:

默认情况下,新的 Google Kubernetes Engine 集群是使用 存储桶的只读权限。设置读写 创建 Google Kubernetes Engine 集群时的存储范围,使用 --scopes 选项。

对于 GCE:

默认情况下,Compute Engine 虚拟机具有只读访问范围 为存储桶配置。要推送私有 Docker 映像,您的 实例必须将读写存储访问范围配置为 访问范围中描述。

首先,验证您的 GKE 集群或 GCE 实例是否确实设置了正确的范围。

接下来是向注册中心进行身份验证:

a) 如果您使用的是基于 Linux 的映像,则需要使用“gcloud auth configure-docker”(https://cloud.google.com/container-registry/docs/advanced-authentication)。

b) 对于 Container-Optimized OS (COS),命令为“docker-credential-gcr configure-docker” (https://cloud.google.com/container-optimized-os/docs/how-to/run-container-instance#accessing_private_google_container_registry)

【讨论】:

  • 您的机器上可能没有docker-credential-gcr。继续使用gcloud components install docker-credential-gcr 安装它,重新打开cmd(如果在Windows 上)并运行docker-credential-gcr configure-docker
【解决方案3】:

https://stackoverflow.com/a/59799035/26283371 所述,Linux 版本的 cloud sdk 中似乎存在一个错误,即使用标准身份验证方法 (gcloud auth configure-docker) 进行身份验证失败。相反,为每个 this 创建一个 JSON 密钥文件,这往往会奏效。

【讨论】:

    【解决方案4】:

    以防万一其他人用头撞墙,我的 PIA VPN 导致了这种行为。

    "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"
    

    关闭我的 VPN,它就可以正常工作了。重新打开它,它又会坏掉。

    【讨论】:

      【解决方案5】:

      如果您以 root 身份运行 docker(即使用 sudo docker),请确保将身份验证配置为 root。例如,您可以运行:

      sudo -s
      gcloud auth login
      gcloud auth configure-docker
      

      ...这将在/root/.docker/config.json 下创建(或更新)一个文件。

      gcloud auth loginroot 有任何安全隐患吗?在 cmets 中告诉我。)

      【讨论】:

        【解决方案6】:

        Windows / Powershell

        当我在安装 SDK 时打开的谷歌云 shell 中进行身份验证后尝试从普通的 powershell 窗口运行 docker push 时,我在 Windows 上遇到了这个错误。

        解决方法很简单:

        运行gcloud auth configure-docker命令后启动一个新的powershell窗口运行docker push

        确保您也已激活注册表:

        gcloud services enable containerregistry.googleapis.com
        

        此外,Google 倾向于跳转到默认帐户,该帐户可能是您想要的,也可能不是。如果您在浏览器中打开任何链接,请确保您使用的是正确的 Google 帐户。

        我还不确定发生了什么,因为我是 docker 的新手,但是在启动一个新的 Powershell 实例时有些东西得到了刷新。

        【讨论】:

          【解决方案7】:

          我仍然无法让 gcloud auth configure-docker 助手工作。所做的是使用access token 进行身份验证,就像这样

          gcloud auth print-access-token | docker login -u oauth2accesstoken --password-stdin https://HOSTNAME 
          

          其中 HOSTNAME 是 gcr.ious.gcr.ioeu.gcr.ioasia.gcr.io。 (一定要包含https://,否则不起作用)。

          您可以查看print-access-token here 的选项。

          【讨论】:

            【解决方案8】:

            这是唯一对我有用的方法。我在一个 kubernetes/kompose Github 问题中找到了它。

            1. 删除~/.docker/config.json 中的credsStore

            当您使用docker login 时,这将强制 docker 将身份验证写入 json。您不能再在 docker 桌面上取消选中 Securely store Docker logins in macOS keychain 了——而且当前的 credStore 不再是 macOS 钥匙串,而是 desktop

            1. gcloud auth login 使用 gcloud 进行身份验证(只是为了明确)
            2. gcloud auth print-access-token | docker login -u oauth2accesstoken --password-stdin https://eu.gcr.io

            你应该看到这个:

            WARNING! Your password will be stored unencrypted in /Users/andrew/.docker/config.json.
            Configure a credential helper to remove this warning. See
            https://docs.docker.com/engine/reference/commandline/login/#credentials-store
            
            Login Succeeded
            

            来源:https://github.com/kubernetes/kompose/issues/1043#issuecomment-609019141

            【讨论】:

              【解决方案9】:

              修复如下:运行gcloud auth login(浏览器将打开并允许您进行身份验证)然后运行gcloud auth configure-docker并选择Y - 然后重做推送。它应该像魅力一样发挥作用。

              【讨论】:

                猜你喜欢
                • 2021-01-04
                • 2017-03-01
                • 2021-04-22
                • 2020-11-22
                • 2017-09-23
                • 2014-07-13
                • 2021-09-20
                • 2017-05-13
                • 2020-06-21
                相关资源
                最近更新 更多