Docker@1 - Docker v1 任务

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

注释

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

语法

# Docker v1
# Build, tag, push, or run Docker images, or run a Docker command.
- task: Docker@1
  inputs:
  # Container Registry
    #containerregistrytype: 'Azure Container Registry' # 'Azure Container Registry' | 'Container Registry'. Required when command != logout. Container registry type. Default: Azure Container Registry.
    #dockerRegistryEndpoint: # string. Optional. Use when containerregistrytype = Container Registry && command != logout. Docker registry service connection. 
    #azureSubscriptionEndpoint: # string. Optional. Use when containerregistrytype = Azure Container Registry && command != logout. Azure subscription. 
    #azureContainerRegistry: # string. Optional. Use when containerregistrytype = Azure Container Registry && command != logout. Azure container registry. 
  # Commands
    #addBaseImageData: true # boolean. Add base image metadata to image(s). Default: true.
    command: 'Build an image' # 'Build an image' | 'Tag image' | 'Push an image' | 'Run an image' | 'login' | 'logout'. Required. Command. Default: Build an image.
    #dockerFile: '**/Dockerfile' # string. Required when command = Build an image || command = build. Dockerfile. Default: **/Dockerfile.
    #arguments: # string. Optional. Use when command != login && command != logout. Arguments. 
    #pushMultipleImages: false # boolean. Optional. Use when command = Push an image || command = push. Push multiple images. Default: false.
    #tagMultipleImages: false # boolean. Optional. Use when command = Tag image || command = tag. Tag multiple images. Default: false.
    #imageName: '$(Build.Repository.Name):$(Build.BuildId)' # string. Required when command = Build an image || command = build || command = Run an image || command = run || pushMultipleImages = false || tagMultipleImages = false. Image name. Default: $(Build.Repository.Name):$(Build.BuildId).
    #imageNamesPath: # string. Required when tagMultipleImages = true || pushMultipleImages = true. Image names path. 
    #qualifyImageName: true # boolean. Optional. Use when command = Build an image || command = build || command = Tag image || command = tag || command = Push an image || command = push || command = Run an image || command = run. Qualify image name. Default: true.
    #qualifySourceImageName: false # boolean. Optional. Use when command = Tag image || command = tag. Qualify source image name. Default: false.
    #includeSourceTags: false # boolean. Optional. Use when command = Build an image || command = build || command = Tag image || command = tag  || command = Push an image || command = push. Include source tags. Default: false.
    #includeLatestTag: false # boolean. Optional. Use when command = Build an image || command = build. Include latest tag. Default: false.
    #addDefaultLabels: true # boolean. Optional. Use when addDefaultLabels = false. Add default labels. Default: true.
    #useDefaultContext: true # boolean. Optional. Use when command = Build an image || command = build. Use default build context. Default: true.
    #buildContext: # string. Optional. Use when useDefaultContext = false. Build context. 
    #imageDigestFile: # string. Optional. Use when command = Push an image || command = push. Image digest file. 
    #containerName: # string. Optional. Use when command = Run an image || command = run. Container name. 
    #ports: # string. Optional. Use when command = Run an image || command = run. Ports. 
    #volumes: # string. Optional. Use when command = Run an image || command = run. Volumes. 
    #envVars: # string. Optional. Use when command = Run an image || command = run. Environment variables. 
    #workingDirectory: # string. Optional. Use when command = Run an image || command = run. Working directory. 
    #entrypointOverride: # string. Optional. Use when command = Run an image || command = run. Entry point override. 
    #containerCommand: # string. Optional. Use when command = Run an image || command = run. Container command. 
    #runInBackground: true # boolean. Optional. Use when command = Run an image || command = run. Run in background. Default: true.
    restartPolicy: 'no' # 'no' | 'onFailure' | 'always' | 'unlessStopped'. Required when runInBackground = true. Restart policy. Default: no.
    #maxRestartRetries: # string. Optional. Use when runInBackground = true && restartPolicy = onFailure. Maximum restart retries. 
  # Advanced Options
    #dockerHostEndpoint: # string. Optional. Use when command != login && command != logout. Docker host service connection. 
    #enforceDockerNamingConvention: true # boolean. Optional. Use when command != login && command != logout. Force image name to follow Docker naming convention. Default: true.
    #memoryLimit: # string. Optional. Use when command != login && command != logout. Memory limit.
# Docker v1
# Build, tag, push, or run Docker images, or run a Docker command.
- task: Docker@1
  inputs:
  # Container Registry
    #containerregistrytype: 'Azure Container Registry' # 'Azure Container Registry' | 'Container Registry'. Required when command != logout. Container registry type. Default: Azure Container Registry.
    #dockerRegistryEndpoint: # string. Optional. Use when containerregistrytype = Container Registry && command != logout. Docker registry service connection. 
    #azureSubscriptionEndpoint: # string. Optional. Use when containerregistrytype = Azure Container Registry && command != logout. Azure subscription. 
    #azureContainerRegistry: # string. Optional. Use when containerregistrytype = Azure Container Registry && command != logout. Azure container registry. 
  # Commands
    command: 'Build an image' # 'Build an image' | 'Tag image' | 'Push an image' | 'Run an image' | 'login' | 'logout'. Required. Command. Default: Build an image.
    #dockerFile: '**/Dockerfile' # string. Required when command = Build an image || command = build. Dockerfile. Default: **/Dockerfile.
    #arguments: # string. Optional. Use when command != login && command != logout. Arguments. 
    #pushMultipleImages: false # boolean. Optional. Use when command = Push an image || command = push. Push multiple images. Default: false.
    #tagMultipleImages: false # boolean. Optional. Use when command = Tag image || command = tag. Tag multiple images. Default: false.
    #imageName: '$(Build.Repository.Name):$(Build.BuildId)' # string. Required when command = Build an image || command = build || command = Run an image || command = run || pushMultipleImages = false || tagMultipleImages = false. Image name. Default: $(Build.Repository.Name):$(Build.BuildId).
    #imageNamesPath: # string. Required when tagMultipleImages = true || pushMultipleImages = true. Image names path. 
    #qualifyImageName: true # boolean. Optional. Use when command = Build an image || command = build || command = Tag image || command = tag || command = Push an image || command = push || command = Run an image || command = run. Qualify image name. Default: true.
    #qualifySourceImageName: false # boolean. Optional. Use when command = Tag image || command = tag. Qualify source image name. Default: false.
    #includeSourceTags: false # boolean. Optional. Use when command = Build an image || command = build || command = Tag image || command = tag  || command = Push an image || command = push. Include source tags. Default: false.
    #includeLatestTag: false # boolean. Optional. Use when command = Build an image || command = build. Include latest tag. Default: false.
    #addDefaultLabels: true # boolean. Optional. Use when addDefaultLabels = false. Add default labels. Default: true.
    #useDefaultContext: true # boolean. Optional. Use when command = Build an image || command = build. Use default build context. Default: true.
    #buildContext: # string. Optional. Use when useDefaultContext = false. Build context. 
    #imageDigestFile: # string. Optional. Use when command = Push an image || command = push. Image digest file. 
    #containerName: # string. Optional. Use when command = Run an image || command = run. Container name. 
    #ports: # string. Optional. Use when command = Run an image || command = run. Ports. 
    #volumes: # string. Optional. Use when command = Run an image || command = run. Volumes. 
    #envVars: # string. Optional. Use when command = Run an image || command = run. Environment variables. 
    #workingDirectory: # string. Optional. Use when command = Run an image || command = run. Working directory. 
    #entrypointOverride: # string. Optional. Use when command = Run an image || command = run. Entry point override. 
    #containerCommand: # string. Optional. Use when command = Run an image || command = run. Container command. 
    #runInBackground: true # boolean. Optional. Use when command = Run an image || command = run. Run in background. Default: true.
    restartPolicy: 'no' # 'no' | 'onFailure' | 'always' | 'unlessStopped'. Required when runInBackground = true. Restart policy. Default: no.
    #maxRestartRetries: # string. Optional. Use when runInBackground = true && restartPolicy = onFailure. Maximum restart retries. 
  # Advanced Options
    #dockerHostEndpoint: # string. Optional. Use when command != login && command != logout. Docker host service connection. 
    #enforceDockerNamingConvention: true # boolean. Optional. Use when command != login && command != logout. Force image name to follow Docker naming convention. Default: true.
    #memoryLimit: # string. Optional. Use when command != login && command != logout. Memory limit.

输入

containerregistrytype - 容器注册表类型
stringcommand != logout时是必需的。 允许的值:Azure Container RegistryContainer Registry。 默认值:Azure Container Registry

指定要使用 Azure 服务连接进行连接的 Azure 容器注册表。 选择 Azure 容器注册表以连接到 Docker 中心或任何其他专用容器注册表。


addBaseImageData - 向图像添加基础映像元数据
boolean。 默认值:true

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


dockerRegistryEndpoint - Docker 注册表服务连接
string。 可选。 当 containerregistrytype = Container Registry && command != logout时使用。

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


azureSubscriptionEndpoint - Azure 订阅
string。 可选。 当 containerregistrytype = Azure Container Registry && command != logout时使用。

指定 Azure 订阅。


azureContainerRegistry - Azure 容器注册表
string。 可选。 当 containerregistrytype = Azure Container Registry && command != logout时使用。

指定所选 Azure 订阅中的 Azure 容器注册表。 容器映像生成并推送到此容器注册表。


command - 命令
string。 必填。 允许的值:Build an image(build)、Tag image(tag)、Push an image(push)、Run an image(run)、loginlogout。 默认值:Build an image

指定要运行的 docker 命令。


dockerFile - Dockerfile 文件
stringcommand = Build an image || command = build时是必需的。 默认值:**/Dockerfile

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


arguments - 参数
string。 可选。 当 command != login && command != logout时使用。

指定要传递给 docker 客户端的其他参数。 使用命令参数中的值 buildAndPush 将忽略参数属性。


pushMultipleImages - 推送多个映像
boolean。 可选。 当 command = Push an image || command = push时使用。 默认值:false

指定要推送的 Docker 映像文本文件中的列表。 以单独的行 Imagename1:tag1 格式列出每个图像名称。 列出没有标记的图像名称(例如 Imagename2)会推送 Imagename2 容器中的所有标记。


tagMultipleImages - 标记多个映像
boolean。 可选。 当 command = Tag image || command = tag时使用。 默认值:false

指定要在文本文件中标记的多个映像标记和 Docker 映像的列表。 以单独的行 Imagename1:tag1 格式列出每个图像名称。 默认情况下,没有标记为 Imagename2 的映像将标记为最新


imageName - 映像名称
stringcommand = Build an image || command = build || command = Run an image || command = run || pushMultipleImages = false || tagMultipleImages = false时是必需的。 默认值:$(Build.Repository.Name):$(Build.BuildId)

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


imageNamesPath - 映像名称路径
stringtagMultipleImages = true || pushMultipleImages = true时是必需的。

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


qualifyImageName - 限定映像名称
boolean。 可选。 当 command = Build an image || command = build || command = Tag image || command = tag || command = Push an image || command = push || command = Run an image || command = run时使用。 默认值:true

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


qualifySourceImageName - 限定源映像名称
boolean。 可选。 当 command = Tag image || command = tag时使用。 默认值:false

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


includeSourceTags - 包括源标记
boolean。 可选。 当 command = Build an image || command = build || command = Tag image || command = tag || command = Push an image || command = push时使用。 默认值:false

指定要在生成或推送 Docker 映像时包括的 Git 标记。


includeLatestTag - 包括最新标记
boolean。 可选。 当 command = Build an image || command = build时使用。 默认值:false

指定在生成 Docker 映像时是否使用 最新 标记。


addDefaultLabels - 添加默认标签
boolean。 可选。 当 addDefaultLabels = false时使用。 默认值:true

指定是否使用 Docker 标签(如存储库、提交、生成和发布信息)将 CI/CD 元数据添加到容器映像。


useDefaultContext - 使用默认生成上下文
boolean。 可选。 当 command = Build an image || command = build时使用。 默认值:true

指定在包含 Docker 文件的目录中添加或删除生成上下文。


buildContext - 生成上下文
string。 可选。 当 useDefaultContext = false时使用。

指定生成上下文的路径。


imageDigestFile - 图像摘要文件
string。 可选。 当 command = Push an image || command = push时使用。

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


containerName - 容器名称
string。 可选。 当 command = Run an image || command = run时使用。

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


ports - 端口
string。 可选。 当 command = Run an image || command = run时使用。

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


volumes -
string。 可选。 当 command = Run an image || command = run时使用。

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


envVars - 环境变量
string。 可选。 当 command = Run an image || command = run时使用。

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


workingDirectory - 工作目录
string。 可选。 当 command = Run an image || command = run时使用。

指定 Docker 容器的工作目录。


entrypointOverride - 入口点替代
string。 可选。 当 command = Run an image || command = run时使用。

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


containerCommand - 容器命令
string。 可选。 当 command = Run an image || command = run时使用。

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


runInBackground - 在后台 中运行
boolean。 可选。 当 command = Run an image || command = run时使用。 默认值:true

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


restartPolicy - 重启策略
stringrunInBackground = true时是必需的。 允许的值:noonFailure(失败时)、alwaysunlessStopped(除非停止)。 默认值:no

指定何时运行重启策略。


maxRestartRetries - 最大重启重试次数
string。 可选。 当 runInBackground = true && restartPolicy = onFailure时使用。

指定 Docker 守护程序尝试的重启次数上限。


dockerHostEndpoint - Docker 主机服务连接
string。 可选。 当 command != login && command != logout时使用。

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


enforceDockerNamingConvention - 强制映像名称遵循 Docker 命名约定
boolean。 可选。 当 command != login && command != logout时使用。 默认值:true

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


memoryLimit - 内存限制
string。 可选。 当 command != login && command != logout时使用。

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


任务控制选项

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

输出变量

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

DockerOutput
存储 docker 命令的输出

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

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

DockerOutput
存储 docker 命令的输出

注解

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

要求

要求 说明
管道类型 YAML,经典版本,经典版本
运行时间 代理,DeploymentGroup
需求 没有
功能 此任务不满足作业中后续任务的任何要求。
命令限制 任何
Settable 变量 任何
代理版本 所有支持的代理版本。
任务类别 建造

另请参阅