这是我的 dev.yml,它是用于开发环境的天蓝色管道:
# Docker
# Build and push an image to Azure Container Registry
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker
trigger:
- dev
resources:
- repo: self
variables:
# Container registry service connection established during pipeline creation
dockerRegistryServiceConnection: '53d49b4c-9b33-4d35-b5f7-44d8554a609a'
imageRepository: 'apidevloyaledge'
containerRegistry: 'devsahasholdingcr.azurecr.io'
dockerfilePath: '$(Build.SourcesDirectory)/Dockerfile'
tag: '$(Build.BuildId)'
pool:
name: builders
stages:
- stage: Build
displayName: Build the image
jobs:
- job: Build
displayName: Build
steps:
- task: PublishPipelineArtifact@1
inputs:
targetPath: 'docker-compose.yml'
artifact: 'docker-compose'
publishLocation: 'pipeline'
- task: Docker@2
displayName: Build
inputs:
containerRegistry: '$(dockerRegistryServiceConnection)'
repository: '$(imageRepository)'
command: 'build'
Dockerfile: 'Dockerfile'
tags: '$(tag)'
- stage: Push
displayName: Push the image
jobs:
- job: Push
displayName: Push
steps:
- task: Docker@2
displayName: Push an image to container registry
inputs:
containerRegistry: '$(dockerRegistryServiceConnection)'
repository: '$(imageRepository)'
command: 'push'
tags: '$(tag)'
- stage: DeployToServer
displayName: Deploy
jobs:
- deployment: dockerDeployment
displayName: Deployment to dev environment
environment:
name: dev
pool:
name: dev
demands: Agent.Name -equals dev-1
strategy:
runOnce:
deploy:
steps:
- task: DownloadPipelineArtifact@2
inputs:
buildType: 'current'
artifactName: 'docker-compose'
targetPath: '.'
- task: DockerCompose@0
inputs:
containerregistrytype: 'Azure Container Registry'
azureSubscription: 'Microsoft Azure Sponsorship(e6037dae-cb96-472a-a3a9-809f0b83ba39)'
azureContainerRegistry: '{"loginServer":"devsahasholdingcr.azurecr.io", "id" : "/subscriptions/e6037dae-cb96-472a-a3a9-809f0b83ba39/resourceGroups/dev/providers/Microsoft.ContainerRegistry/registries/devsahasholdingcr"}'
dockerComposeFile: 'docker-compose.yml'
dockerComposeFileArgs: 'tag = $(tag)'
action: 'Run a Docker Compose command'
dockerComposeCommand: 'up'
arguments: '-d api-dev-loyaledge'
这是我的 docker-compose 文件:
version: "3.9"
services:
api-dev-loyaledge:
image: devsahasholdingcr.azurecr.io/apidevloyaledge:${tag}
container_name: api-dev-loyaledge
network_mode: "host"
restart: unless-stopped
environment:
- ASPNETCORE_ENVIRONMENT=Development
api-testing-loyaledge:
image: testingsahasholdingcr.azurecr.io/apitestingloyaledge:${tag}
container_name: api-testing-loyaledge
network_mode: "host"
restart: unless-stopped
environment:
- ASPNETCORE_ENVIRONMENT=testing
当我的管道到达 Docker compose 任务时,会发生以下错误:
我尝试将 docker-compose 文件版本更新为 3.9,并且我已将部署服务器中的 docker-compose 版本更新为 2.12.2。以前相同的管道运行良好。
这是一个已知问题,应该是由 DockerCompose@0 任务最近更新引起的。请参阅“DockerCompose@0 在 v1 兼容模式下使用 Docker Compose v2”。