Search code examples
azure-devopsyamlazure-pipelines-yamldocker-registrybuildx

Is it possible to build multi-architecture docker images via pipeline


I am trying to create one image that supports amd64 and arm64 in my DevOps pipeline but get this error:

ERROR: Multi-platform build is not supported for the docker driver. Switch to a different driver, or turn on the containerd image store, and try again.

This is how I am attempting to do it:

  - task: DockerInstaller@0
    displayName: 'Install Docker'
    inputs:
      dockerVersion: '27.0.3'

  - task: PowerShell@2
    displayName: 'Set up Docker Buildx and QEMU'
    inputs:
      targetType: 'inline'
      script: |
        docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
        docker buildx create --name mybuilder --driver docker-container --use
        docker buildx inspect --bootstrap

  - task: Docker@2
    displayName: 'Build multi-arch image'
    inputs:
      command: build
      containerRegistry: 'acrName'
      repository: ${{ parameters.repository }}
      tags: |
        ${{ parameters.imageTag }}
      Dockerfile: ${{ parameters.dockerfile }}  
      buildContext: ${{ parameters.context }}
      arguments: '--platform linux/amd64,linux/arm64'

  - task: Docker@2
    displayName: 'Push multi-arch image to ACR'
    inputs:
      command: push
      containerRegistry: 'acrName'
      repository: ${{ parameters.repository }}
      tags: |
        ${{ parameters.imageTag }}

Solution

  • I can reproduce the same error with your yaml sample.

    enter image description here

    Buildx is an experimental feature that allows you to build images for multiple architectures. Need to enable experimental features in Docker.

    You can add variable in yaml, which will automatically mapped as environment.

    variables:
      DOCKER_CLI_EXPERIMENTAL: 'true'
    

    in addition, the task Docker@2 uses docker build ... command, not docker buildx build... command, hence, please remove the task, use command directly.

    - powershell: docker buildx build --platform linux/amd64,linux/arm64 -t myimage:latest .
    

    Pipeline result on my side:

    enter image description here

    Then you can push to ACR.

    Please refer to below links here and here for the details: