使用 Azure DevOps Pipelines 和 docker-compose 构建和推送 docker 镜像到 ACR 时出现身份验证错误

时间:2021-06-22 12:00:50

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

我正在尝试使用 Azure DevOps 管道构建 docker 映像并将其推送到 ACR。我必须使用 docker-compose.yml 文件构建它才能在容器中使用 openvpn。

当我运行管道时,出现以下错误。有没有人知道如何解决这个问题?

Starting: DockerCompose
==============================================================================
Task         : Docker Compose
Description  : Build, push or run multi-container Docker applications. Task can be used with Docker or Azure Container registry.
Version      : 0.183.0
Author       : Microsoft Corporation
Help         : https://aka.ms/azpipes-docker-compose-tsg
==============================================================================
/usr/local/bin/docker-compose -f /home/vsts/work/1/s/src/docker-compose.yml -f /home/vsts/agents/2.188.2/.docker-compose.1624362077551.yml -p Compose up -d
Creating network "composeproject_default" with the default driver
Pulling getstatus (***/getstatus:)...
Head https://***/v2/getstatus/manifests/latest: unauthorized: authentication required, visit https://aka.ms/acr/authorization for more information.
##[error]Creating network "composeproject_default" with the default driver
##[error]Pulling getstatus (***/getstatus:)...
##[error]Head https://***/v2/getstatus/manifests/latest: unauthorized: authentication required, visit https://aka.ms/acr/authorization for more information.
##[error]The process '/usr/local/bin/docker-compose' failed with exit code 1
Finishing: DockerCompose

我的 azure-pipelines.yml 如下所示:

# Docker
# Build and push an image to Azure Container Registry
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker

trigger:
- main

resources:
- repo: self

variables:
  # Container registry service connection established during pipeline creation
  dockerRegistryServiceConnection: '*****************************'
  imageRepository: 'getstatus'
  containerRegistry: 'composeproject.azurecr.io'
  dockerfilePath: '$(Build.SourcesDirectory)/Dockerfile'
  tag: '$(Build.BuildId)'

  # Agent VM image name
  vmImageName: 'ubuntu-latest'


stages:
- stage: Build
  displayName: Build and push stage
  jobs:
  - job: Build
    displayName: Build
    pool:
      vmImage: $(vmImageName)
    steps:

    - task: Docker@2
      displayName: Build and push an image to container registry
      inputs:
        command: buildAndPush
        repository: $(imageRepository)
        dockerfile: $(dockerfilePath)
        containerRegistry: $(dockerRegistryServiceConnection)
        tags: |
          $(tag)

    - task: DockerCompose@0
      inputs:
        containerregistrytype: 'Azure Container Registry'
        dockerComposeFile: '**/docker-compose.yml'
        action: 'Run a Docker Compose command'
        dockerComposeCommand: 'up -d'

和 docker-compose.yml 像这样:

version: "3.3"
services: 
  getstatus:
    image: composeproject.azurecr.io/getstatus
    restart: always
    sysctls:
      - net.ipv6.conf.all.disable_ipv6=0
    cap_add: 
      - NET_ADMIN
    devices:
      - /dev/net/tun
    volumes:
      - /etc/timezone:/etc/timezone:ro

1 个答案:

答案 0 :(得分:1)

我认为您的 docker compose 任务是 missing a couple of parameters

尝试添加 azureContainerRegistry: composeproject.azurecr.ioazureSubscriptionEndpoint: $(dockerRegistryServiceConnection)

不确定为什么在 Docker@2 任务中提供的凭据不存在,因为它们处于同一阶段,但随后我可以用我不确定的 Azure 管道填充百科全书

>