在 Azure "unauthorized: authentication required" 中将 Docker 图像任务推送到 ACR 失败
Push Docker Image task to ACR fails in Azure "unauthorized: authentication required"
Azure DevOps 管道中的推送和映像到 Azure 容器注册表任务失败。以前的任务执行得很好,即。 docker 图像已创建并成功登录 ACR。但是,推送任务失败,结果如下:
unauthorized: authentication required
[error]unauthorized: authentication required
[error]/usr/bin/docker failed with return code: 1
[section]Finishing: Push Docker image
docker 从本地命令行推送到给定的 acr 工作正常。
# Docker image
# Build a Docker image to deploy, run, or push to a container registry.
# Add steps that use Docker Compose, tag images, push to a registry, run an image, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker
trigger:
- master
pool:
vmImage: 'Ubuntu-16.04'
variables:
imageName: 'renamed:$(build.buildId)'
azureSubscriptionEndpoint: Renamed
azureContainerRegistry: renamed.azurecr.io
steps:
- task: Docker@1
displayName: Build docker image
inputs:
command: Build an image
dockerFile: Dockerfile
imageName: $(imageName)
containerregistrytype: Azure Container Registry
azureSubscriptionEndpoint: $(azureSubscriptionEndpoint)
azureContainerRegistry: $(azureContainerRegistry)
- task: Docker@1
displayName: Login to container registry
inputs:
command: login
containerregistrytype: Azure Container Registry
azureSubscriptionEndpoint: $(azureSubscriptionEndpoint)
azureContainerRegistry: $(azureContainerRegistry)
dockerFile: Dockerfile
imageName: $(imageName)
- task: Docker@1
displayName: Push Docker image
inputs:
command: Push an image
containerregistrytype: Azure Container Registry
azureSubscriptionEndpoint: $(azureSubscriptionEndpoint)
azureContainerRegistry: $(azureContainerRegistry)
imageName: $(imageName)
从您的构建中删除 docker 登录步骤,docker 任务使用 azure 订阅端点(如果配置正确)为您处理身份验证,如果没有 - 将您的服务主体权限授予 acrpush
).
我在 Azure DevOps 中使用 Azure 容器注册表服务连接时遇到了同样的问题。
解决方法是在创建 Docker 注册表服务连接时不选择“Azure 容器注册表”,而是选择“其他”。然后在 Azure 门户中启用容器注册表上的管理员用户,并使用其中的凭据创建服务连接。
转到项目设置 --> 服务连接 --> 编辑 --> 重新验证权限
应该可以解决问题
在我的例子中,我用 433 标记我的图像。
例如:<containerRegistryName>.azurecr.io:443/<imageName>
去掉433后,再次尝试推送,成功了!
我在将 docker 图像推送到 Azure 容器注册表 时遇到了这个问题。
我收到错误
unauthorized: authentication required, visit https://aka.ms/acr/authorization for more information.
这是我修复它的方法:
我的用户已经拥有 Container Registry 的 Owner 角色,因此我有权推送和拉取图像。
问题是 admin_user
未在 Azure 容器注册表中启用。
我所要做的就是启用管理员用户。这会生成 username
、password
和 password2
.
接下来,您现在可以使用以下命令登录到 Azure 容器注册表:
az acr login --name my-container-registry
标记您的 docker 图片
docker tag image-name:image-tag my-container-registry.azurecr.io/image-name:image-tag
现在使用以下命令将图像推送到 Azure 容器注册表:
docker push my-container-registry.azurecr.io/image-name:image-tag
就这些了
区分大小写问题
我创建了一个 ACR 名称:blaH
我可以登录:az acr login -n blaH
Uppercase characters are detected in the registry name. When using its server url in docker commands, to avoid authentication errors, use all lowercase.
Login Succeeded
docker build -f Dockerfile -t blaH.azurecr.io/some-app:1.0 ..
unauthorized: authentication required, visit https://aka.ms/acr/authorization for more information.
切换为小写 h
,即 docker build -f Dockerfile -t blah.azurecr.io/some-app:1.0 ..
& 成功:
1.0: digest: sha256:b1e6749eae625e6a3fca3eea36466530460e8cd544af67e88687139a37522ba6 size: 1495
注意: 它甚至告诉 me/us 但我没有读它 ♂️,请参阅 acr login
上 CLI 中以黄色打印的警告.
注 2: 我在查看 Azure 门户网站时偶然发现了这一点,并注意到 login server
全部为小写:
Azure DevOps 管道中的推送和映像到 Azure 容器注册表任务失败。以前的任务执行得很好,即。 docker 图像已创建并成功登录 ACR。但是,推送任务失败,结果如下:
unauthorized: authentication required
[error]unauthorized: authentication required
[error]/usr/bin/docker failed with return code: 1
[section]Finishing: Push Docker image
docker 从本地命令行推送到给定的 acr 工作正常。
# Docker image
# Build a Docker image to deploy, run, or push to a container registry.
# Add steps that use Docker Compose, tag images, push to a registry, run an image, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker
trigger:
- master
pool:
vmImage: 'Ubuntu-16.04'
variables:
imageName: 'renamed:$(build.buildId)'
azureSubscriptionEndpoint: Renamed
azureContainerRegistry: renamed.azurecr.io
steps:
- task: Docker@1
displayName: Build docker image
inputs:
command: Build an image
dockerFile: Dockerfile
imageName: $(imageName)
containerregistrytype: Azure Container Registry
azureSubscriptionEndpoint: $(azureSubscriptionEndpoint)
azureContainerRegistry: $(azureContainerRegistry)
- task: Docker@1
displayName: Login to container registry
inputs:
command: login
containerregistrytype: Azure Container Registry
azureSubscriptionEndpoint: $(azureSubscriptionEndpoint)
azureContainerRegistry: $(azureContainerRegistry)
dockerFile: Dockerfile
imageName: $(imageName)
- task: Docker@1
displayName: Push Docker image
inputs:
command: Push an image
containerregistrytype: Azure Container Registry
azureSubscriptionEndpoint: $(azureSubscriptionEndpoint)
azureContainerRegistry: $(azureContainerRegistry)
imageName: $(imageName)
从您的构建中删除 docker 登录步骤,docker 任务使用 azure 订阅端点(如果配置正确)为您处理身份验证,如果没有 - 将您的服务主体权限授予 acrpush
).
我在 Azure DevOps 中使用 Azure 容器注册表服务连接时遇到了同样的问题。
解决方法是在创建 Docker 注册表服务连接时不选择“Azure 容器注册表”,而是选择“其他”。然后在 Azure 门户中启用容器注册表上的管理员用户,并使用其中的凭据创建服务连接。
转到项目设置 --> 服务连接 --> 编辑 --> 重新验证权限
应该可以解决问题
在我的例子中,我用 433 标记我的图像。
例如:<containerRegistryName>.azurecr.io:443/<imageName>
去掉433后,再次尝试推送,成功了!
我在将 docker 图像推送到 Azure 容器注册表 时遇到了这个问题。
我收到错误
unauthorized: authentication required, visit https://aka.ms/acr/authorization for more information.
这是我修复它的方法:
我的用户已经拥有 Container Registry 的 Owner 角色,因此我有权推送和拉取图像。
问题是 admin_user
未在 Azure 容器注册表中启用。
我所要做的就是启用管理员用户。这会生成 username
、password
和 password2
.
接下来,您现在可以使用以下命令登录到 Azure 容器注册表:
az acr login --name my-container-registry
标记您的 docker 图片
docker tag image-name:image-tag my-container-registry.azurecr.io/image-name:image-tag
现在使用以下命令将图像推送到 Azure 容器注册表:
docker push my-container-registry.azurecr.io/image-name:image-tag
就这些了
区分大小写问题
我创建了一个 ACR 名称:blaH
我可以登录:az acr login -n blaH
Uppercase characters are detected in the registry name. When using its server url in docker commands, to avoid authentication errors, use all lowercase.
Login Succeeded
docker build -f Dockerfile -t blaH.azurecr.io/some-app:1.0 ..
unauthorized: authentication required, visit https://aka.ms/acr/authorization for more information.
切换为小写 h
,即 docker build -f Dockerfile -t blah.azurecr.io/some-app:1.0 ..
& 成功:
1.0: digest: sha256:b1e6749eae625e6a3fca3eea36466530460e8cd544af67e88687139a37522ba6 size: 1495
注意: 它甚至告诉 me/us 但我没有读它 ♂️,请参阅 acr login
上 CLI 中以黄色打印的警告.
注 2: 我在查看 Azure 门户网站时偶然发现了这一点,并注意到 login server
全部为小写: