Docker@1 - Docker v1 task

Build, tag, push, or run Docker images, or run a Docker command. Use this task with Docker or the Azure Container registry.

Note

Docker@2 is a newer version of this task that simplifies the task by removing inputs that can be passed as arguments to the command.

Syntax

# 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.
# 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.
    #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 can be used with Docker or Azure Container registry.
- 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 != Run an image && command != run && command != login && command != logout. Arguments. 
    #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. 
    #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.
    #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 command = Build an image || command = build. Add default labels. Default: true.
    #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. 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.

Inputs

containerregistrytype - Container registry type
string. Required when command != logout. Allowed values: Azure Container Registry, Container Registry. Default value: Azure Container Registry.

Specifies the Azure Container Registry to connect using an Azure Service Connection. Select an Azure Container Registry to connect to a Docker Hub or any other private container registry.


addBaseImageData - Add base image metadata to image(s)
boolean. Default value: true.

The default value adds base image data, such as the base image name and digest, to help with traceability. You can opt out of this default behavior by setting this value to false.


dockerRegistryEndpoint - Docker registry service connection
string. Optional. Use when containerregistrytype = Container Registry && command != logout.

Specifies a Docker registry service connection. Required for commands that authenticate using a registry.


azureSubscriptionEndpoint - Azure subscription
string. Optional. Use when containerregistrytype = Azure Container Registry && command != logout.

Specifies an Azure subscription.


azureContainerRegistry - Azure container registry
string. Optional. Use when containerregistrytype = Azure Container Registry && command != logout.

Specifies an Azure Container Registry in the selected Azure Subscription. The container image is built and pushed to this container registry.


command - Command
string. Required. Allowed values: Build an image (build), Tag image (tag), Push an image (push), Run an image (run), login, logout. Default value: Build an image.

Specifies the docker command to run.


dockerFile - Dockerfile
string. Required when command = Build an image || command = build. Default value: **/Dockerfile.

Specifies the path to the Docker file. The task uses the first docker file it finds to build the image.


arguments - Arguments
string. Optional. Use when command != login && command != logout.

Specifies additional arguments to pass to the docker client. Using the value buildAndPush in the command parameter ignores the arguments property.


arguments - Arguments
string. Optional. Use when command != Run an image && command != run && command != login && command != logout.

Specifies additional arguments to pass to the docker client. Using the value buildAndPush in the command parameter ignores the arguments property.


pushMultipleImages - Push multiple images
boolean. Optional. Use when command = Push an image || command = push. Default value: false.

Specifies a list in a text file of Docker images to push. List each image name in the format Imagename1:tag1 on a separate line. Listing an image name without tags, for example Imagename2, pushes all tags in the Imagename2 container.


tagMultipleImages - Tag multiple images
boolean. Optional. Use when command = Tag image || command = tag. Default value: false.

Specifies a list of multiple image tags and Docker images to tag in a text file. List each image name in the format Imagename1:tag1 on a separate line. Images listed without a tag as Imagename2 are tagged as latest by default.


imageName - Image name
string. Required when command = Build an image || command = build || command = Run an image || command = run || pushMultipleImages = false || tagMultipleImages = false. Default value: $(Build.Repository.Name):$(Build.BuildId).

Specifies the name of the Docker image to build, push, or run.


imageNamesPath - Image names path
string. Required when tagMultipleImages = true || pushMultipleImages = true.

Specifies the path to a text file that contains the names of the Docker images to tag or push. List each image name on a separate line.


qualifyImageName - Qualify image name
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. Default value: true.

Specifies a qualify image name with the Docker registry service connection's hostname.


qualifySourceImageName - Qualify source image name
boolean. Optional. Use when command = Tag image || command = tag. Default value: false.

Specifies a qualify image name with the Docker registry service connection's hostname.


includeSourceTags - Include source tags
boolean. Optional. Use when command = Build an image || command = build || command = Tag image || command = tag || command = Push an image || command = push. Default value: false.

Specifies Git tags to include when building or pushing the Docker image.


includeLatestTag - Include latest tag
boolean. Optional. Use when command = Build an image || command = build. Default value: false.

Specifies whether to use the latest tag when building the Docker image.


addDefaultLabels - Add default labels
boolean. Optional. Use when addDefaultLabels = false. Default value: true.

Specifies whether to add CI/CD metadata to the container image by using Docker labels, like repository, commit, build and release information.


addDefaultLabels - Add default labels
boolean. Optional. Use when command = Build an image || command = build. Default value: true.

Specifies whether to add CI/CD metadata to the container image by using Docker labels, like repository, commit, build and release information.


useDefaultContext - Use default build context
boolean. Optional. Use when command = Build an image || command = build. Default value: true.

Specifies adding or removing build context to the directory that contains the Docker file.


buildContext - Build context
string. Optional. Use when useDefaultContext = false.

Specifies the path to the build context.


imageDigestFile - Image digest file
string. Optional. Use when command = Push an image || command = push.

Specifies the path to a file that is created and populated with the full image repository digest of the Docker image that was pushed.


containerName - Container name
string. Optional. Use when command = Run an image || command = run.

Specifies the name of the Docker container to run.


ports - Ports
string. Optional. Use when command = Run an image || command = run.

Specifies the ports in the Docker container to publish to the host. List each host-port:container-port binding on a separate line.


volumes - Volumes
string. Optional. Use when command = Run an image || command = run.

Specifies the volumes to mount from the host. List each host-dir:container-dir on a separate line.


envVars - Environment variables
string. Optional. Use when command = Run an image || command = run.

Specifies environment variables for the Docker container. List each name=value pair on a separate line.


workingDirectory - Working directory
string. Optional. Use when command = Run an image || command = run.

Specifies the working directory for the Docker container.


entrypointOverride - Entry point override
string. Optional. Use when command = Run an image || command = run.

Specifies whether to override the default entry point for the Docker container.


containerCommand - Container command
string. Optional. Use when command = Run an image || command = run.

Specifies a Docker run command. The docker run command first creates a writeable container layer over the specified image, and then starts it by using the specified run command. For example, if the image contains a simple Python Flask web application you can specify python app.py to launch the web application.


containerCommand - Command
string. Optional. Use when command = Run an image || command = run.

Specifies a Docker run command. The docker run command first creates a writeable container layer over the specified image, and then starts it by using the specified run command. For example, if the image contains a simple Python Flask web application you can specify python app.py to launch the web application.


runInBackground - Run in background
boolean. Optional. Use when command = Run an image || command = run. Default value: true.

Specifies whether to run the Docker container in the background.


restartPolicy - Restart policy
string. Required when runInBackground = true. Allowed values: no, onFailure (On failure), always, unlessStopped (Unless stopped). Default value: no.

Specifies when to run a restart policy.


maxRestartRetries - Maximum restart retries
string. Optional. Use when runInBackground = true && restartPolicy = onFailure.

Specifies the maximum number of restart retries the Docker daemon attempts.


dockerHostEndpoint - Docker host service connection
string. Optional. Use when command != login && command != logout.

Specifies a Docker host service connection. Defaults to the agent's host.


enforceDockerNamingConvention - Force image name to follow Docker naming convention
boolean. Optional. Use when command != login && command != logout. Default value: true.

The default value modifies the Docker image name according to Docker naming conventions. For example, convert upper case characters to lower case and remove spaces.


memoryLimit - Memory limit
string. Optional. Use when command != login && command != logout.

Specifies the maximum amount of memory available to the container as an integer with optional suffixes like 2GB.


Task control options

All tasks have control options in addition to their task inputs. For more information, see Control options and common task properties.

Output variables

This task defines the following output variables, which you can consume in downstream steps, jobs, and stages.

DockerOutput
Stores the output of the docker command

DockerOutputPath
The path of the file which contains the output of the build command.

This task defines the following output variables, which you can consume in downstream steps, jobs, and stages.

DockerOutput
Stores the output of the docker command

Remarks

Docker@2 is a newer version of this task that simplifies the task by removing inputs that can be passed as arguments to the command.

Requirements

Requirement Description
Pipeline types YAML, Classic build, Classic release
Runs on Agent, DeploymentGroup
Demands None
Capabilities This task does not satisfy any demands for subsequent tasks in the job.
Command restrictions Any
Settable variables Any
Agent version All supported agent versions.
Task category Build

See also