How to Build and Push a Docker Image in Azure Pipelines
Azure Pipelines builds and pushes images with the Docker@2 task and a registry service connection.
Create a Docker Registry service connection, then use the Docker@2 task with command: buildAndPush, referencing the connection and a tag.
Build and push with Docker@2
The task builds from the Dockerfile and pushes to the connected registry, tagged at the build ID.
azure-pipelines.yml
steps:
- task: Docker@2
displayName: Build and push
inputs:
command: buildAndPush
containerRegistry: 'acr-connection'
repository: 'myorg/app'
dockerfile: '**/Dockerfile'
tags: |
$(Build.BuildId)
latestGotchas
- The
containerRegistryvalue is the name of a service connection, not a registry URL - create it in Project settings. buildAndPushis one command; do not separately addbuildthenpushtasks with the same inputs.- For multi-arch builds, add a
Docker@2command: loginthen drivedocker buildxvia a script step.
Related guides
How to Build and Push a Docker Image in GitHub ActionsBuild and push a Docker image in GitHub Actions with docker/build-push-action - log in to GHCR, set tags, and…
How to Authenticate Azure Pipelines with Workload Identity (OIDC)Authenticate Azure Pipelines to Azure with a workload identity federation service connection - short-lived OI…