如何解决通过 azure 管道部署时 docker-compose 文件中的卷装载问题的变量替换?

How to resolve the variable substitution for volume mount issue in docker-compose file when deploying through azure pipeline?

我有一个 docker-compose 文件

version: "3.6"
services:
    web:
        image: p21d01.azurecr.io/web1:latest
        env_file:
          - ./test.env
        volumes:
          - "${BASE_MOUNT_PATH}/config:${BASE_FILEPROCESSING_PATH}"

docker compose 文件也有一个 env 文件,该文件具有文件挂载变量的值

test.env

####Mounting#######
BASE_MOUNT_PATH=/opt/docker/folder1
BASE_FILEPROCESSING_PATH=/opt/processing

我在 azure pipeline yaml 中使用以下代码到 运行 容器

  - task: DockerCompose@0
    displayName: Run a Docker Compose command
    inputs:
      containerregistrytype: 'Container Registry'
      action: Run a Docker Compose command
      #azureSubscriptionEndpoint: $(azureSubscriptionEndpoint)
      #azureContainerRegistry: $(azureContainerRegistry)
      dockerComposeFile: '$(Pipeline.Workspace)/s/docker_compose/docker-compose.yaml'
      dockerComposeCommand: '--env-file $(Pipeline.Workspace)/s/docker_compose/test.env up -d'

我在 运行 连接管道时收到以下错误。上面的代码虽然成功创建了容器,但它抛出以下错误并且没有卷挂载发生

##[error]The BASE_MOUNT_PATH variable is not set. Defaulting to a blank string.
##[error]The BASE_FILEPROCESSING_PATH variable is not set. Defaulting to a blank string.

以上代码在手动 运行 时工作正常。但是在使用上面的代码时,会出现上面提到的错误。请帮助解决这个错误

您需要将它们作为环境映射,如下所示:

- task: DockerCompose@0
    displayName: Run a Docker Compose command
    inputs:
      containerregistrytype: 'Container Registry'
      action: Run a Docker Compose command
      #azureSubscriptionEndpoint: $(azureSubscriptionEndpoint)
      #azureContainerRegistry: $(azureContainerRegistry)
      dockerComposeFile: '$(Pipeline.Workspace)/s/docker_compose/docker-compose.yaml'
      dockerComposeCommand: '--env-file $(Pipeline.Workspace)/s/docker_compose/test.env up -d'
    env:
      BASE_MOUNT_PATH:'/opt/docker/folder1'
      BASE_FILEPROCESSING_PATH:'/opt/processing'

它将在构建代码的代理上创建环境变量。