gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 17:14:28 24 4
gpt4 key购买 nike

我有一个 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 文件,它有文件挂载变量的值

测试环境

####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'

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

关于docker - 通过 azure 管道部署时,如何解决 docker-compose 文件中卷装载问题的变量替换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68932970/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com