DockerCompose@0 - Docker Compose v0 任务
生成、推送或运行多容器 Docker 应用程序。 将此任务与 Docker 或 Azure 容器注册表一起使用。
语法
# Docker Compose v0
# Build, push or run multi-container Docker applications. Task can be used with Docker or Azure Container registry.
- task: DockerCompose@0
inputs:
containerregistrytype: 'Azure Container Registry' # 'Azure Container Registry' | 'Container Registry'. Required. Container Registry Type. Default: Azure Container Registry.
#dockerRegistryEndpoint: # string. Optional. Use when containerregistrytype = Container Registry. Docker Registry Service Connection.
#azureSubscription: # string. Alias: azureSubscriptionEndpoint. Optional. Use when containerregistrytype = Azure Container Registry. Azure subscription.
#azureContainerRegistry: # string. Optional. Use when containerregistrytype = Azure Container Registry. Azure Container Registry.
dockerComposeFile: '**/docker-compose.yml' # string. Required. Docker Compose File. Default: **/docker-compose.yml.
#additionalDockerComposeFiles: # string. Additional Docker Compose Files.
#dockerComposeFileArgs: # string. Environment Variables.
#projectName: '$(Build.Repository.Name)' # string. Project Name. Default: $(Build.Repository.Name).
#qualifyImageNames: true # boolean. Qualify Image Names. Default: true.
action: 'Run a Docker Compose command' # 'Build services' | 'Push services' | 'Run services' | 'Run a specific service' | 'Lock services' | 'Write service image digests' | 'Combine configuration' | 'Run a Docker Compose command'. Required. Action. Default: Run a Docker Compose command.
#additionalImageTags: # string. Optional. Use when action = Build services || action = Push services. Additional Image Tags.
#includeSourceTags: false # boolean. Optional. Use when action = Build services || action = Push services. Include Source Tags. Default: false.
#includeLatestTag: false # boolean. Optional. Use when action = Build services || action = Push services. Include Latest Tag. Default: false.
#buildImages: true # boolean. Optional. Use when action = Run services. Build Images. Default: true.
#serviceName: # string. Required when action = Run a specific service. Service Name.
#containerName: # string. Optional. Use when action = Run a specific service. Container Name.
#ports: # string. Optional. Use when action = Run a specific service. Ports.
#workingDirectory: # string. Alias: workDir. Optional. Use when action = Run a specific service. Working Directory.
#entrypoint: # string. Optional. Use when action = Run a specific service. Entry Point Override.
#containerCommand: # string. Optional. Use when action = Run a specific service. Command.
#detached: true # boolean. Optional. Use when action = Run services || action = Run a specific service. Run in Background. Default: true.
#abortOnContainerExit: true # boolean. Optional. Use when action = Run services && detached == false. Abort on Container Exit. Default: true.
#imageDigestComposeFile: '$(Build.StagingDirectory)/docker-compose.images.yml' # string. Required when action = Write service image digests. Image Digest Compose File. Default: $(Build.StagingDirectory)/docker-compose.images.yml.
#removeBuildOptions: false # boolean. Optional. Use when action = Lock services || action = Combine configuration. Remove Build Options. Default: false.
#baseResolveDirectory: # string. Optional. Use when action = Lock services || action = Combine configuration. Base Resolve Directory.
#outputDockerComposeFile: '$(Build.StagingDirectory)/docker-compose.yml' # string. Required when action = Lock services || action = Combine configuration. Output Docker Compose File. Default: $(Build.StagingDirectory)/docker-compose.yml.
#dockerComposeCommand: # string. Required when action = Run a Docker Compose command. Command.
#arguments: # string. Optional. Use when action != Lock services && action != Combine configuration && action != Write service image digests. Arguments.
# Advanced Options
#dockerHostEndpoint: # string. Docker Host Service Connection.
#nopIfNoDockerComposeFile: false # boolean. No-op if no Docker Compose File. Default: false.
#requireAdditionalDockerComposeFiles: false # boolean. Require Additional Docker Compose Files. Default: false.
#currentWorkingDirectory: '$(System.DefaultWorkingDirectory)' # string. Alias: cwd. Working Directory. Default: $(System.DefaultWorkingDirectory).
#dockerComposePath: # string. Docker Compose executable Path.
# Docker Compose v0
# Build, push or run multi-container Docker applications. Task can be used with Docker or Azure Container registry.
- task: DockerCompose@0
inputs:
containerregistrytype: 'Azure Container Registry' # 'Azure Container Registry' | 'Container Registry'. Required. Container Registry Type. Default: Azure Container Registry.
#dockerRegistryEndpoint: # string. Optional. Use when containerregistrytype = Container Registry. Docker Registry Service Connection.
#azureSubscription: # string. Alias: azureSubscriptionEndpoint. Optional. Use when containerregistrytype = Azure Container Registry. Azure subscription.
#azureContainerRegistry: # string. Optional. Use when containerregistrytype = Azure Container Registry. Azure Container Registry.
dockerComposeFile: '**/docker-compose.yml' # string. Required. Docker Compose File. Default: **/docker-compose.yml.
#additionalDockerComposeFiles: # string. Additional Docker Compose Files.
#dockerComposeFileArgs: # string. Environment Variables.
#projectName: '$(Build.Repository.Name)' # string. Project Name. Default: $(Build.Repository.Name).
#qualifyImageNames: true # boolean. Qualify Image Names. Default: true.
action: 'Run a Docker Compose command' # 'Build services' | 'Push services' | 'Run services' | 'Run a specific service' | 'Lock services' | 'Write service image digests' | 'Combine configuration' | 'Run a Docker Compose command'. Required. Action. Default: Run a Docker Compose command.
#additionalImageTags: # string. Optional. Use when action = Build services || action = Push services. Additional Image Tags.
#includeSourceTags: false # boolean. Optional. Use when action = Build services || action = Push services. Include Source Tags. Default: false.
#includeLatestTag: false # boolean. Optional. Use when action = Build services || action = Push services. Include Latest Tag. Default: false.
#buildImages: true # boolean. Optional. Use when action = Run services. Build Images. Default: true.
#serviceName: # string. Required when action = Run a specific service. Service Name.
#containerName: # string. Optional. Use when action = Run a specific service. Container Name.
#ports: # string. Optional. Use when action = Run a specific service. Ports.
#workingDirectory: # string. Alias: workDir. Optional. Use when action = Run a specific service. Working Directory.
#entrypoint: # string. Optional. Use when action = Run a specific service. Entry Point Override.
#containerCommand: # string. Optional. Use when action = Run a specific service. Command.
#detached: true # boolean. Optional. Use when action = Run services || action = Run a specific service. Run in Background. Default: true.
#abortOnContainerExit: true # boolean. Optional. Use when action = Run services && detached == false. Abort on Container Exit. Default: true.
#imageDigestComposeFile: '$(Build.StagingDirectory)/docker-compose.images.yml' # string. Required when action = Write service image digests. Image Digest Compose File. Default: $(Build.StagingDirectory)/docker-compose.images.yml.
#removeBuildOptions: false # boolean. Optional. Use when action = Lock services || action = Combine configuration. Remove Build Options. Default: false.
#baseResolveDirectory: # string. Optional. Use when action = Lock services || action = Combine configuration. Base Resolve Directory.
#outputDockerComposeFile: '$(Build.StagingDirectory)/docker-compose.yml' # string. Required when action = Lock services || action = Combine configuration. Output Docker Compose File. Default: $(Build.StagingDirectory)/docker-compose.yml.
#dockerComposeCommand: # string. Required when action = Run a Docker Compose command. Command.
#arguments: # string. Optional. Use when action != Lock services && action != Combine configuration && action != Write service image digests. Arguments.
# Advanced Options
#dockerHostEndpoint: # string. Docker Host Service Connection.
#nopIfNoDockerComposeFile: false # boolean. No-op if no Docker Compose File. Default: false.
#requireAdditionalDockerComposeFiles: false # boolean. Require Additional Docker Compose Files. Default: false.
#currentWorkingDirectory: '$(System.DefaultWorkingDirectory)' # string. Alias: cwd. Working Directory. Default: $(System.DefaultWorkingDirectory).
# Docker Compose v0
# Build, push or run multi-container Docker applications. Task can be used with Docker or Azure Container registry.
- task: DockerCompose@0
inputs:
containerregistrytype: 'Azure Container Registry' # 'Azure Container Registry' | 'Container Registry'. Required. Container Registry Type. Default: Azure Container Registry.
#dockerRegistryEndpoint: # string. Optional. Use when containerregistrytype = Container Registry. Docker Registry Service Connection.
#azureSubscription: # string. Alias: azureSubscriptionEndpoint. Optional. Use when containerregistrytype = Azure Container Registry. Azure subscription.
#azureContainerRegistry: # string. Optional. Use when containerregistrytype = Azure Container Registry. Azure Container Registry.
dockerComposeFile: '**/docker-compose.yml' # string. Required. Docker Compose File. Default: **/docker-compose.yml.
#additionalDockerComposeFiles: # string. Additional Docker Compose Files.
#dockerComposeFileArgs: # string. Environment Variables.
#projectName: '$(Build.Repository.Name)' # string. Project Name. Default: $(Build.Repository.Name).
#qualifyImageNames: true # boolean. Qualify Image Names. Default: true.
action: 'Run a Docker Compose command' # 'Build services' | 'Push services' | 'Run services' | 'Run a specific service' | 'Lock services' | 'Write service image digests' | 'Combine configuration' | 'Run a Docker Compose command'. Required. Action. Default: Run a Docker Compose command.
#additionalImageTags: # string. Optional. Use when action = Build services || action = Push services. Additional Image Tags.
#includeSourceTags: false # boolean. Optional. Use when action = Build services || action = Push services. Include Source Tags. Default: false.
#includeLatestTag: false # boolean. Optional. Use when action = Build services || action = Push services. Include Latest Tag. Default: false.
#buildImages: true # boolean. Optional. Use when action = Run services. Build Images. Default: true.
#serviceName: # string. Required when action = Run a specific service. Service Name.
#containerName: # string. Optional. Use when action = Run a specific service. Container Name.
#ports: # string. Optional. Use when action = Run a specific service. Ports.
#workingDirectory: # string. Alias: workDir. Optional. Use when action = Run a specific service. Working Directory.
#entrypoint: # string. Optional. Use when action = Run a specific service. Entry Point Override.
#containerCommand: # string. Optional. Use when action = Run a specific service. Command.
#detached: true # boolean. Optional. Use when action = Run services || action = Run a specific service. Run in Background. Default: true.
#abortOnContainerExit: true # boolean. Optional. Use when action = Run services && detached == false. Abort on Container Exit. Default: true.
#imageDigestComposeFile: '$(Build.StagingDirectory)/docker-compose.images.yml' # string. Required when action = Write service image digests. Image Digest Compose File. Default: $(Build.StagingDirectory)/docker-compose.images.yml.
#removeBuildOptions: false # boolean. Optional. Use when action = Lock services || action = Combine configuration. Remove Build Options. Default: false.
#baseResolveDirectory: # string. Optional. Use when action = Lock services || action = Combine configuration. Base Resolve Directory.
#outputDockerComposeFile: '$(Build.StagingDirectory)/docker-compose.yml' # string. Required when action = Lock services || action = Combine configuration. Output Docker Compose File. Default: $(Build.StagingDirectory)/docker-compose.yml.
#dockerComposeCommand: # string. Required when action = Run a Docker Compose command. Command.
# Advanced Options
#dockerHostEndpoint: # string. Docker Host Service Connection.
#nopIfNoDockerComposeFile: false # boolean. No-op if no Docker Compose File. Default: false.
#requireAdditionalDockerComposeFiles: false # boolean. Require Additional Docker Compose Files. Default: false.
#currentWorkingDirectory: '$(System.DefaultWorkingDirectory)' # string. Alias: cwd. Working Directory. Default: $(System.DefaultWorkingDirectory).
输入
containerregistrytype
- 容器注册表类型
string
. 必需。 允许的值:Azure Container Registry
、Container Registry
。 默认值:Azure Container Registry
。
如果使用 ACR,则指定Azure 容器注册表类型。 如果使用任何其他容器注册表,请指定容器注册表类型。
dockerRegistryEndpoint
- Docker 注册表服务连接
string
. 可选。 在 时 containerregistrytype = Container Registry
使用 。
指定 Docker 注册表服务连接。 当命令需要使用注册表进行身份验证时是必需的。
azureSubscription
- Azure 订阅
输入别名: azureSubscriptionEndpoint
。 string
. 可选。 在 时 containerregistrytype = Azure Container Registry
使用 。
指定 Azure 订阅。 Azure 服务连接的名称。 若要手动设置连接,请参阅 Azure 资源管理器服务连接。
azureContainerRegistry
- Azure 容器注册表
string
. 可选。 在 时 containerregistrytype = Azure Container Registry
使用 。
指定Azure 容器注册表。
dockerComposeFile
- Docker Compose 文件
string
. 必需。 默认值:**/docker-compose.yml
。
指定主 Docker Compose 文件的文件路径。
additionalDockerComposeFiles
- 其他 Docker Compose 文件
string
.
指定与主 Docker Compose 文件组合的其他 Docker Compose 文件。 将相对于包含主 Docker Compose 文件的目录解析相对路径。 如果未找到指定的文件,则忽略此参数。 在新行中指定每个文件路径。
dockerComposeFileArgs
- 环境变量
string
.
指定设置的任何环境变量。
格式如下:
- 列出新行上的每
name=value
对。 |
在 YAML 中使用 运算符保留新行。
projectName
- 项目名称
string
. 默认值:$(Build.Repository.Name)
。
指定默认用于命名映像和容器的项目名称。
qualifyImageNames
- 限定映像名称
boolean
. 默认值:true
。
默认情况下, 指定 Docker 注册表服务连接的主机名。
action
- 行动
string
. 必需。 允许的值: Build services
(生成服务映像) , Push services
(推送服务映像) , Run services
(运行服务映像) , Run a specific service
(运行特定的服务映像) , Lock services
(锁定服务映像) 、、Write service image digests
Combine configuration
、Run a Docker Compose command
。 默认值:Run a Docker Compose command
。
指定允许值列表中的 Docker Compose 操作。
additionalImageTags
- 其他映像标记
string
. 可选。 在 时 action = Build services || action = Push services
使用 。
为正在生成或推送的 Docker 映像指定其他标记。 可以指定多个标记,用换行 \n
符分隔每个标记。
includeSourceTags
- 包括源标记
boolean
. 可选。 在 时 action = Build services || action = Push services
使用 。 默认值:false
。
指定生成或推送 Docker 映像时的 Git 标记。
includeLatestTag
- 包含最新标记
boolean
. 可选。 在 时 action = Build services || action = Push services
使用 。 默认值:false
。
指定生成或推送 Docker 映像时 的最新 标记。
buildImages
- 生成映像
boolean
. 可选。 在 时 action = Run services
使用 。 默认值:true
。
在启动服务容器之前指定生成映像。
serviceName
- 服务名称
string
. 当 action = Run a specific service
时,需要此选项。
指定要运行的服务的名称。
containerName
- 容器名称
string
. 可选。 在 时 action = Run a specific service
使用 。
指定要使用的服务容器的名称。
ports
- 港口
string
. 可选。 在 时 action = Run a specific service
使用 。
指定要发布到主机的服务容器中的端口。 在新行上添加每个 host-port:container-port
绑定。
workingDirectory
- 工作目录
输入别名: workDir
。 string
. 可选。 在 时 action = Run a specific service
使用 。
指定服务容器的工作目录。
entrypoint
- 入口点替代
string
. 可选。 在 时 action = Run a specific service
使用 。
指定服务容器的默认入口点的替代值。
containerCommand
- 命令
string
. 可选。 在 时 action = Run a specific service
使用 。
指定要在服务容器中运行的命令。 例如,如果映像包含简单的 Python Flask Web 应用程序,则可以指定 python app.py
以启动 Web 应用程序。
detached
- 在后台运行
boolean
. 可选。 在 时 action = Run services || action = Run a specific service
使用 。 默认值:true
。
指定要在后台运行的服务容器。
abortOnContainerExit
- 容器退出时中止
boolean
. 可选。 在 时 action = Run services && detached == false
使用 。 默认值:true
。
指定在任何容器退出时应停止的所有容器。
imageDigestComposeFile
- 图像摘要撰写文件
string
. 当 action = Write service image digests
时,需要此选项。 默认值:$(Build.StagingDirectory)/docker-compose.images.yml
。
指定 Docker Compose 文件的路径,该文件使用每个服务的 Docker 映像的完整映像存储库摘要创建和填充。
removeBuildOptions
- 删除生成选项
boolean
. 可选。 在 时 action = Lock services || action = Combine configuration
使用 。 默认值:false
。
指定是否应从输出 Docker Compose 文件中删除生成选项。
baseResolveDirectory
- 基本解析目录
string
. 可选。 在 时 action = Lock services || action = Combine configuration
使用 。
指定应从中解析输出 Docker Compose 文件中的相对路径的基目录。
outputDockerComposeFile
- 输出 Docker Compose 文件
string
. 当 action = Lock services || action = Combine configuration
时,需要此选项。 默认值:$(Build.StagingDirectory)/docker-compose.yml
。
指定输出 Docker Compose 文件的路径。
dockerComposeCommand
- 命令
string
. 当 action = Run a Docker Compose command
时,需要此选项。
指定要使用参数执行的 Docker Compose 命令。 例如, rm --all
删除所有已停止的服务容器。
arguments
- 参数
string
. 可选。 在 时 action != Lock services && action != Combine configuration && action != Write service image digests
使用 。
指定 Docker Compose 命令选项。
示例:对于生成命令,为 --pull --compress --parallel
。
dockerHostEndpoint
- Docker 主机服务连接
string
.
指定 Docker 主机服务连接。 默认为代理的主机。
nopIfNoDockerComposeFile
- 如果没有 Docker Compose 文件,则为 No-op
boolean
. 默认值:false
。
指定在 Docker Compose 文件不存在时跳过任务的值。 当任务根据存储库中是否存在 Docker Compose 文件提供可选行为时,此选项非常有用。
requireAdditionalDockerComposeFiles
- 需要其他 Docker Compose 文件
boolean
. 默认值:false
。
指定一个值,当其他 Docker Compose 文件不存在时,将产生错误。 此选项替代默认行为,如果文件不存在,则会忽略该文件。
currentWorkingDirectory
- 工作目录
输入别名: cwd
。 string
. 默认值:$(System.DefaultWorkingDirectory)
。
指定 Docker Compose 命令的工作目录。
dockerComposePath
- Docker Compose 可执行路径
string
.
指定用于确定是否使用 docker-compose 可执行文件的路径。
任务控制选项
除了任务输入,所有任务都有控制选项。 有关详细信息,请参阅 控制选项和常见任务属性。
输出变量
此任务定义以下 输出变量,可在下游步骤、作业和阶段中使用。
DockerComposeOutput
包含命令输出的文件的路径。 这可能包含多个文件路径 (用换行符分隔) 例如,dockerComposeRun 命令 (一个用于运行,一个用于向下) ,dockerPush (一个用于) 推送的每个映像,dockerBuild (生成本身以及所有标记命令) 和 dockerDigest () 拉取的每个映像。 其他命令仅输出一个文件。
无。
备注
使用此任务生成、推送或运行多容器 Docker 应用程序。 将此任务与 Docker 注册表或Azure 容器注册表一起使用。
示例
Azure 容器注册表
此 YAML 示例指定Azure 容器注册表的输入:
variables:
azureContainerRegistry: Contoso.azurecr.io
azureSubscriptionEndpoint: Contoso
steps:
- task: DockerCompose@0
displayName: Container registry login
inputs:
containerregistrytype: Azure Container Registry
azureSubscriptionEndpoint: $(azureSubscriptionEndpoint)
azureContainerRegistry: $(azureContainerRegistry)
其他容器注册表
使用除 ACR 以外的任何容器注册表时,都需要 containerregistrytype 值。 containerregistrytype: Container Registry
在本例中使用 。
此 YAML 示例指定 ACR 以外的容器注册表,其中 Contoso 是容器注册表的 Docker 注册表服务连接的名称:
- task: DockerCompose@0
displayName: Container registry login
inputs:
containerregistrytype: Container Registry
dockerRegistryEndpoint: Contoso
生成服务映像
此 YAML 示例生成映像,其中映像名称根据与 Azure 容器注册表相关的输入进行限定:
- task: DockerCompose@0
displayName: Build services
inputs:
action: Build services
azureSubscriptionEndpoint: $(azureSubscriptionEndpoint)
azureContainerRegistry: $(azureContainerRegistry)
dockerComposeFile: docker-compose.yml
projectName: $(Build.Repository.Name)
qualifyImageNames: true
additionalImageTags: $(Build.BuildId)
dockerComposeFileArgs: |
firstArg=$(firstArg)
secondArg=$(secondArg)
推送服务映像
此 YAML 示例将映像推送到容器注册表:
- task: DockerCompose@0
displayName: Push services
inputs:
action: Push services
azureSubscriptionEndpoint: $(azureSubscriptionEndpoint)
azureContainerRegistry: $(azureContainerRegistry)
dockerComposeFile: docker-compose.yml
projectName: $(Build.Repository.Name)
qualifyImageNames: true
additionalImageTags: $(Build.BuildId)
运行服务映像
此 YAML 示例运行服务:
- task: DockerCompose@0
displayName: Run services
inputs:
action: Run services
azureSubscriptionEndpoint: $(azureSubscriptionEndpoint)
azureContainerRegistry: $(azureContainerRegistry)
dockerComposeFile: docker-compose.ci.build.yml
projectName: $(Build.Repository.Name)
qualifyImageNames: true
buildImages: true
abortOnContainerExit: true
detached: true
运行特定的服务映像
此 YAML 示例运行特定服务:
- task: DockerCompose@0
displayName: Run a specific service
inputs:
action: Run a specific service
azureSubscriptionEndpoint: $(azureSubscriptionEndpoint)
azureContainerRegistry: $(azureContainerRegistry)
dockerComposeFile: docker-compose.yml
projectName: $(Build.Repository.Name)
qualifyImageNames: true
serviceName: myhealth.web
ports: 80:80
detached: true
锁定服务映像
此 YAML 示例锁定服务:
- task: DockerCompose@0
displayName: Lock services
inputs:
action: Lock services
azureSubscriptionEndpoint: $(azureSubscriptionEndpoint)
azureContainerRegistry: $(azureContainerRegistry)
dockerComposeFile: docker-compose.yml
projectName: $(Build.Repository.Name)
qualifyImageNames: true
outputDockerComposeFile: $(Build.StagingDirectory)/docker-compose.yml
编写服务映像摘要
此 YAML 示例编写服务映像摘要:
- task: DockerCompose@0
displayName: Write service image digests
inputs:
action: Write service image digests
azureSubscriptionEndpoint: $(azureSubscriptionEndpoint)
azureContainerRegistry: $(azureContainerRegistry)
dockerComposeFile: docker-compose.yml
projectName: $(Build.Repository.Name)
qualifyImageNames: true
imageDigestComposeFile: $(Build.StagingDirectory)/docker-compose.images.yml
合并配置
此 YAML 示例合并了配置:
- task: DockerCompose@0
displayName: Combine configuration
inputs:
action: Combine configuration
azureSubscriptionEndpoint: $(azureSubscriptionEndpoint)
azureContainerRegistry: $(azureContainerRegistry)
dockerComposeFile: docker-compose.yml
additionalDockerComposeFiles: docker-compose.override.yml
projectName: $(Build.Repository.Name)
qualifyImageNames: true
outputDockerComposeFile: $(Build.StagingDirectory)/docker-compose.yml
运行 Docker Compose 命令
此 YAML 示例运行 docker Compose 命令:
- task: DockerCompose@0
displayName: Run a Docker Compose command
inputs:
action: Run a Docker Compose command
azureSubscriptionEndpoint: $(azureSubscriptionEndpoint)
azureContainerRegistry: $(azureContainerRegistry)
dockerComposeFile: docker-compose.yml
projectName: $(Build.Repository.Name)
qualifyImageNames: true
dockerComposeCommand: rm