docker - 将容器推送到 Azure 容器注册表时拒绝资源访问

标签 docker docker-compose azure-devops devops azure-container-registry

使用 Docker Compose 将容器推送到私有(private) Azure 容器注册表时,Azure DevOps 管道返回以下错误:

Pushing [container] ([registry]/[app]:latest)...

The push refers to repository [docker.io/[registry]/[container]]

denied: requested access to the resource is denied

azure-pipeline.yml 文件取自 Microsoft 微服务 eShopOnContainer 示例中显示的 Docker Compose 示例,here :

variables:
azureContainerRegistry: myregistry
azureSubscriptionEndpoint: My Service Principle
...
task: DockerCompose@0
    displayName: Compose push customer API
    inputs:
        containerregistrytype: Azure Container Registry
        azureSubscriptionEndpoint: $(azureSubscriptionEndpoint)
        azureContainerRegistry: $(azureContainerRegistry)
        dockerComposeCommand: 'push [container]'
        dockerComposeFile: docker-compose.yml
        qualifyImageNames: true
        projectName: ""
        dockerComposeFileArgs: |
           TAG=$(Build.SourceBranchName)

服务原则在AcrPush role .

最佳答案

解决方案是明确容器名称。 documentation具有误导性,因为它首先声明:containerregistrytype 默认为 Azure Container Registry。该示例继续将 Contoso 作为 azureContainerRegistry 的值。

这是错误的。您需要将其显式设置为 Azure 中的“登录服务器”值。因此注册表应该是“contoso.azurecr.io”。所以完整的例子应该是:

variables:
azureContainerRegistry: contoso.azurecr.io
azureSubscriptionEndpoint: Contoso
steps:
- task: DockerCompose@0
  displayName: Container registry login
  inputs:
      containerregistrytype: Azure Container Registry
      azureSubscriptionEndpoint: $(azureSubscriptionEndpoint)
      azureContainerRegistry: $(azureContainerRegistry)

这就是为什么它所指的推送 repo 实际上是:docker.io(公共(public) docker hub),因为它实际上必须是默认的,它解释了访问被拒绝的错误。

关于docker - 将容器推送到 Azure 容器注册表时拒绝资源访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55421635/

相关文章:

azure-devops - Azure DevOps 管道测试显示部分成功

ruby - Rails:在任何源中都找不到 concurrent-ruby-1.0.5 (Bundler::GemNotFound)

仅来自基本镜像的入口点的 Dockerfile

laravel - Dockerize Laravel流明

docker - nginx proxy_pass 不适用于主机文件

azure-devops - Azure DevOps : Is it possible to nest yaml templates inside another yaml template?

python - 如何从 Dockerfile 安装 Python 3.7 和 Pip

java - 带有 Spring Boot 应用程序的 Docker 卡在 RaspberryPi 上的 AnnotationConfigServletWebServerApplicationContext

docker - 当我尝试将 mysql 与 nodejs 连接时,我的 docker-compose 无法正常工作

git - TFS 2018 将工作项与没有 pull 请求的提交相关联