Skip to content
Latchkey

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)
        latest

Gotchas

  • The containerRegistry value is the name of a service connection, not a registry URL - create it in Project settings.
  • buildAndPush is one command; do not separately add build then push tasks with the same inputs.
  • For multi-arch builds, add a Docker@2 command: login then drive docker buildx via a script step.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →