Docker@0 - Docker v0 任务

生成、标记、推送、运行 Docker 映像或运行 Docker 命令。 将此任务与 Docker 或 Azure 容器注册表一起使用。

注意

Docker@2 是此任务的较新版本,它通过删除可以作为参数传递给命令的输入来简化任务。

语法

# Docker v0
# Build, tag, push, or run Docker images, or run a Docker command.
- task: Docker@0
  inputs:
    containerregistrytype: 'Azure Container Registry' # 'Azure Container Registry' | 'Container Registry'. Required. Container Registry Type. Default: Azure Container Registry.
    #dockerRegistryConnection: # string. Alias: dockerRegistryEndpoint. 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. 
    action: 'Build an image' # 'Build an image' | 'Tag images' | 'Push an image' | 'Push images' | 'Run an image' | 'Run a Docker command'. Required. Action. Default: Build an image.
    #dockerFile: '**/Dockerfile' # string. Required when action = Build an image. Docker File. Default: **/Dockerfile.
    #buildArguments: # string. Optional. Use when action = Build an image. Build Arguments. 
    #defaultContext: true # boolean. Optional. Use when action = Build an image. Use Default Build Context. Default: true.
    #context: # string. Optional. Use when action = Build an image && defaultContext = false. Build Context. 
    #imageName: '$(Build.Repository.Name):$(Build.BuildId)' # string. Required when action == Build an image || action == Push an image || action == Run an image. Image Name. Default: $(Build.Repository.Name):$(Build.BuildId).
    #imageNamesPath: # string. Required when action == Tag images || action == Push images. Image Names Path. 
    #qualifyImageName: true # boolean. Optional. Use when action = Build an image || action = Tag images || action = Push an image || action = Push images || action = Run an image. Qualify Image Name. Default: true.
    #additionalImageTags: # string. Optional. Use when action = Build an image || action = Tag images || action = Push an image || action = Push images. Additional Image Tags. 
    #includeSourceTags: false # boolean. Optional. Use when action = Build an image || action = Tag image || action = Push an image || action = Push images. Include Source Tags. Default: false.
    #includeLatestTag: false # boolean. Optional. Use when action = Build an image || action = Push an image || action = Push images. Include Latest Tag. Default: false.
    #imageDigestFile: # string. Optional. Use when action = Push an image || action = Push images. Image Digest File. 
    #containerName: # string. Optional. Use when action = Run an image. Container Name. 
    #ports: # string. Optional. Use when action = Run an image. Ports. 
    #volumes: # string. Optional. Use when action = Run an image. Volumes. 
    #envVars: # string. Optional. Use when action = Run an image. Environment Variables. 
    #workDir: # string. Optional. Use when action = Run an image. Working Directory. 
    #entrypoint: # string. Optional. Use when action = Run an image. Entry Point Override. 
    #containerCommand: # string. Optional. Use when action = Run an image. Command. 
    #detached: true # boolean. Optional. Use when action = Run an image. Run In Background. Default: true.
    #restartPolicy: 'no' # 'no' | 'onFailure' | 'always' | 'unlessStopped'. Required when action = Run an image && detached = true. Restart Policy. Default: no.
    #restartMaxRetries: # string. Optional. Use when action = Run an image && detached = true && restartPolicy = onFailure. Maximum Restart Retries. 
    #customCommand: # string. Required when action = Run a Docker command. Command. 
  # commands
    #addBaseImageData: true # boolean. Add base image metadata to image(s). Default: true.
  # Advanced Options
    #dockerHostEndpoint: # string. Docker Host Service Connection. 
    #enforceDockerNamingConvention: true # boolean. Force image name to follow Docker naming convention. Default: true.
    #workingDirectory: '$(System.DefaultWorkingDirectory)' # string. Alias: cwd. Working Directory. Default: $(System.DefaultWorkingDirectory).
    #memory: # string. Memory limit.
# Docker v0
# Build, tag, push, or run Docker images, or run a Docker command.
- task: Docker@0
  inputs:
    containerregistrytype: 'Azure Container Registry' # 'Azure Container Registry' | 'Container Registry'. Required. Container Registry Type. Default: Azure Container Registry.
    #dockerRegistryConnection: # string. Alias: dockerRegistryEndpoint. 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. 
    action: 'Build an image' # 'Build an image' | 'Tag images' | 'Push an image' | 'Push images' | 'Run an image' | 'Run a Docker command'. Required. Action. Default: Build an image.
    #dockerFile: '**/Dockerfile' # string. Required when action = Build an image. Docker File. Default: **/Dockerfile.
    #buildArguments: # string. Optional. Use when action = Build an image. Build Arguments. 
    #defaultContext: true # boolean. Optional. Use when action = Build an image. Use Default Build Context. Default: true.
    #context: # string. Optional. Use when action = Build an image && defaultContext = false. Build Context. 
    #imageName: '$(Build.Repository.Name):$(Build.BuildId)' # string. Required when action == Build an image || action == Push an image || action == Run an image. Image Name. Default: $(Build.Repository.Name):$(Build.BuildId).
    #imageNamesPath: # string. Required when action == Tag images || action == Push images. Image Names Path. 
    #qualifyImageName: true # boolean. Optional. Use when action = Build an image || action = Tag images || action = Push an image || action = Push images || action = Run an image. Qualify Image Name. Default: true.
    #additionalImageTags: # string. Optional. Use when action = Build an image || action = Tag images || action = Push an image || action = Push images. Additional Image Tags. 
    #includeSourceTags: false # boolean. Optional. Use when action = Build an image || action = Tag image || action = Push an image || action = Push images. Include Source Tags. Default: false.
    #includeLatestTag: false # boolean. Optional. Use when action = Build an image || action = Push an image || action = Push images. Include Latest Tag. Default: false.
    #imageDigestFile: # string. Optional. Use when action = Push an image || action = Push images. Image Digest File. 
    #containerName: # string. Optional. Use when action = Run an image. Container Name. 
    #ports: # string. Optional. Use when action = Run an image. Ports. 
    #volumes: # string. Optional. Use when action = Run an image. Volumes. 
    #envVars: # string. Optional. Use when action = Run an image. Environment Variables. 
    #workDir: # string. Optional. Use when action = Run an image. Working Directory. 
    #entrypoint: # string. Optional. Use when action = Run an image. Entry Point Override. 
    #containerCommand: # string. Optional. Use when action = Run an image. Command. 
    #detached: true # boolean. Optional. Use when action = Run an image. Run In Background. Default: true.
    #restartPolicy: 'no' # 'no' | 'onFailure' | 'always' | 'unlessStopped'. Required when action = Run an image && detached = true. Restart Policy. Default: no.
    #restartMaxRetries: # string. Optional. Use when action = Run an image && detached = true && restartPolicy = onFailure. Maximum Restart Retries. 
    #customCommand: # string. Required when action = Run a Docker command. Command. 
  # Advanced Options
    #dockerHostEndpoint: # string. Docker Host Service Connection. 
    #enforceDockerNamingConvention: true # boolean. Force image name to follow Docker naming convention. Default: true.
    #workingDirectory: '$(System.DefaultWorkingDirectory)' # string. Alias: cwd. Working Directory. Default: $(System.DefaultWorkingDirectory).
    #memory: # string. Memory limit.
# Docker v0
# Build, tag, push, or run Docker images, or run a Docker command. Task can be used with Docker or Azure Container registry.
- task: Docker@0
  inputs:
    containerregistrytype: 'Azure Container Registry' # 'Azure Container Registry' | 'Container Registry'. Required. Container Registry Type. Default: Azure Container Registry.
    #dockerRegistryConnection: # string. Alias: dockerRegistryEndpoint. 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. 
    action: 'Build an image' # 'Build an image' | 'Tag images' | 'Push an image' | 'Push images' | 'Run an image' | 'Run a Docker command'. Required. Action. Default: Build an image.
    #dockerFile: '**/Dockerfile' # string. Required when action = Build an image. Docker File. Default: **/Dockerfile.
    #buildArguments: # string. Optional. Use when action = Build an image. Build Arguments. 
    #defaultContext: true # boolean. Optional. Use when action = Build an image. Use Default Build Context. Default: true.
    #context: # string. Optional. Use when action = Build an image && defaultContext = false. Build Context. 
    #imageName: '$(Build.Repository.Name):$(Build.BuildId)' # string. Required when action == Build an image || action == Push an image || action == Run an image. Image Name. Default: $(Build.Repository.Name):$(Build.BuildId).
    #imageNamesPath: # string. Required when action == Tag images || action == Push images. Image Names Path. 
    #qualifyImageName: true # boolean. Optional. Use when action = Build an image || action = Tag images || action = Push an image || action = Push images || action = Run an image. Qualify Image Name. Default: true.
    #additionalImageTags: # string. Optional. Use when action = Build an image || action = Tag images || action = Push an image || action = Push images. Additional Image Tags. 
    #includeSourceTags: false # boolean. Optional. Use when action = Build an image || action = Tag image || action = Push an image || action = Push images. Include Source Tags. Default: false.
    #includeLatestTag: false # boolean. Optional. Use when action = Build an image || action = Push an image || action = Push images. Include Latest Tag. Default: false.
    #imageDigestFile: # string. Optional. Use when action = Push an image || action = Push images. Image Digest File. 
    #containerName: # string. Optional. Use when action = Run an image. Container Name. 
    #ports: # string. Optional. Use when action = Run an image. Ports. 
    #volumes: # string. Optional. Use when action = Run an image. Volumes. 
    #envVars: # string. Optional. Use when action = Run an image. Environment Variables. 
    #workDir: # string. Optional. Use when action = Run an image. Working Directory. 
    #entrypoint: # string. Optional. Use when action = Run an image. Entry Point Override. 
    #containerCommand: # string. Optional. Use when action = Run an image. Command. 
    #detached: true # boolean. Optional. Use when action = Run an image. Run In Background. Default: true.
    #restartPolicy: 'no' # 'no' | 'onFailure' | 'always' | 'unlessStopped'. Required when action = Run an image && detached = true. Restart Policy. Default: no.
    #restartMaxRetries: # string. Optional. Use when action = Run an image && detached = true && restartPolicy = onFailure. Maximum Restart Retries. 
    #customCommand: # string. Required when action = Run a Docker command. Command. 
  # Advanced Options
    #dockerHostEndpoint: # string. Docker Host Service Connection. 
    #enforceDockerNamingConvention: true # boolean. Force image name to follow Docker naming convention. Default: true.
    #workingDirectory: '$(System.DefaultWorkingDirectory)' # string. Alias: cwd. Working Directory. Default: $(System.DefaultWorkingDirectory).
    #memory: # string. Memory limit.

输入

containerregistrytype - 容器注册表类型
string. 必需。 允许的值:Azure Container RegistryContainer Registry。 默认值:Azure Container Registry

选择“Azure 容器注册表”以使用 Azure 服务连接连接到它。 选择“容器注册表”以连接到Docker Hub或任何其他专用容器注册表。


dockerRegistryConnection - Docker 注册表服务连接
输入别名: dockerRegistryEndpointstring. 可选。 在 时 containerregistrytype = Container Registry使用 。

指定 Docker 注册表服务连接。 所用命令需要使用注册表进行身份验证时必需。


azureSubscription - Azure 订阅
输入别名: azureSubscriptionEndpointstring. 可选。 在 时 containerregistrytype = Azure Container Registry使用 。

指定 Azure 订阅。


azureContainerRegistry - Azure 容器注册表
string. 可选。 在 时 containerregistrytype = Azure Container Registry使用 。

指定所选 Azure 订阅中的Azure 容器注册表。 生成容器映像,然后将其推送到此容器注册表。


action - 行动
string. 必需。 允许的值:Build an image、、Tag imagesPush an imagePush imagesRun an imageRun a Docker command。 默认值:Build an image

指定 Docker 操作。


dockerFile - Docker 文件
string. 当 action = Build an image 时,需要此选项。 默认值:**/Dockerfile

指定 Docker 文件的路径。 任务使用找到的第一个 Docker 文件来生成映像。


addBaseImageData - 将基础图像元数据添加到映像 ()
boolean. 默认值:true

默认值添加基础映像数据,例如基础映像名称和摘要,以帮助实现可跟踪性。 可以通过将 值设置为 false来选择退出。


buildArguments - 生成参数
string. 可选。 在 时 action = Build an image使用 。

指定 Docker 文件的生成时变量。 在新行上设置每 name=value 对的格式。


defaultContext - 使用默认生成上下文
boolean. 可选。 在 时 action = Build an image使用 。 默认值:true

指定包含 Docker 文件的目录的生成上下文。


context - 生成上下文
string. 可选。 在 时 action = Build an image && defaultContext = false使用 。

指定生成上下文的路径。


imageName - 映像名称
string. 当 action == Build an image || action == Push an image || action == Run an image 时,需要此选项。 默认值:$(Build.Repository.Name):$(Build.BuildId)

指定要生成、推送或运行的 Docker 映像的名称。


imageNamesPath - 映像名称路径
string. 当 action == Tag images || action == Push images 时,需要此选项。

指定文本文件的路径,该文件包含要标记或推送的 Docker 映像的名称。 在单独的行中列出每个映像名称。


qualifyImageName - 限定映像名称
boolean. 可选。 在 时 action = Build an image || action = Tag images || action = Push an image || action = Push images || action = Run an image使用 。 默认值:true

使用 Docker 注册表服务连接的主机名指定限定映像名称。


additionalImageTags - 其他映像标记
string. 可选。 在 时 action = Build an image || action = Tag images || action = Push an image || action = Push images使用 。

为正在生成或推送的 Docker 映像指定其他标记。


includeSourceTags - 包括源标记
boolean. 可选。 在 时 action = Build an image || action = Tag image || action = Push an image || action = Push images使用 。 默认值:false

指定在生成或推送 Docker 映像时是否包含 Git 标记。


includeLatestTag - 包含最新标记
boolean. 可选。 在 时 action = Build an image || action = Push an image || action = Push images使用 。 默认值:false

指定在生成或推送 Docker 映像时是否包含 最新 标记。


imageDigestFile - 图像摘要文件
string. 可选。 在 时 action = Push an image || action = Push images使用 。

指定使用推送的 Docker 映像的完整映像存储库摘要创建并填充的文件的路径。


containerName - 容器名称
string. 可选。 在 时 action = Run an image使用 。

指定要运行的 Docker 容器的名称。


ports - 港口
string. 可选。 在 时 action = Run an image使用 。

指定要发布到主机的 Docker 容器中的端口。 列出新行上的每个 host-port:container-port 绑定。


volumes -
string. 可选。 在 时 action = Run an image使用 。

指定要从主机装载的卷。 在新行上列出每个 host-dir:container-dir


envVars - 环境变量
string. 可选。 在 时 action = Run an image使用 。

指定 Docker 容器的环境变量。 列出新行上的每 name=value 对。


workDir - 工作目录
string. 可选。 在 时 action = Run an image使用 。

指定 Docker 容器的工作目录。


entrypoint - 入口点替代
string. 可选。 在 时 action = Run an image使用 。

指定 Docker 容器的默认入口点的替代。


containerCommand - 命令
string. 可选。 在 时 action = Run an image使用 。

指定 Docker run 命令。 docker run 命令首先在指定的映像上创建可写容器层,然后使用指定的 run 命令启动它。 例如,如果映像包含简单的 Python Flask Web 应用程序,则可以指定 python app.py 用于启动 Web 应用程序。


detached - 在后台运行
boolean. 可选。 在 时 action = Run an image使用 。 默认值:true

指定是否在后台运行 Docker 容器。


restartPolicy - 重启策略
string. 当 action = Run an image && detached = true 时,需要此选项。 允许的值: noonFailure (失败) 、 always (unlessStopped 除非停止) 。 默认值:no

指定重启策略。


restartMaxRetries - 最大重启重试次数
string. 可选。 在 时 action = Run an image && detached = true && restartPolicy = onFailure使用 。

指定 Docker 守护程序尝试的最大重启重试次数。


customCommand - 命令
string. 当 action = Run a Docker command 时,需要此选项。

指定要执行的 Docker 命令和参数。 例如, rmi -f image-name 删除图像。


dockerHostEndpoint - Docker 主机服务连接
string.

指定 Docker 主机服务连接。 默认为代理的主机。


enforceDockerNamingConvention - 强制映像名称遵循 Docker 命名约定
boolean. 默认值:true

如果启用,则根据 Docker 命名约定修改 Docker 映像名称。 例如,将大写字符转换为小写并删除空格。


workingDirectory - 工作目录
输入别名: cwdstring. 默认值:$(System.DefaultWorkingDirectory)

指定 Docker 命令的工作目录。


memory - 内存限制
string.

将容器可用的最大内存量指定为具有可选后缀的整数,例如 2GB


任务控制选项

除了任务输入,所有任务都有控制选项。 有关详细信息,请参阅 控制选项和常见任务属性

输出变量

此任务定义以下 输出变量,可在下游步骤、作业和阶段中使用。

DockerOutput
存储 docker 命令的输出。

DockerOutputPath
包含生成命令输出的文件的路径。

此任务定义以下 输出变量,可在下游步骤、作业和阶段中使用。

DockerOutput
存储 docker 命令的输出

注解

Docker@2 是此任务的较新版本,它通过删除可以作为参数传递给命令的输入来简化任务。

要求

要求 说明
管道类型 YAML、经典版本、经典版本
运行平台 Agent、DeploymentGroup
需求
功能 此任务不满足作业中后续任务的任何要求。
命令限制 任意
可设置变量 任意
代理版本 所有支持的代理版本。
任务类别 构建

另请参阅