Back

Contents

Use docker buildx to build multi-architecture images

Building the images and pushing

Get buildx and install, if required: https://docs.docker.com/buildx/working-with-buildx/

Create new QEMU priveleged container/builder:

$ docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
$ docker buildx create --name multiarch --driver docker-container --use

and use the builder to build/push to a repository, e.g. for ghcr

sudo docker buildx build --platform linux/amd64,linux/arm64 --file Dockerfile . --push --tag ghcr.io/<user>/<image>:<tag>

Example Github CI pipeline

You must first create a new action secret personal access token, PAT. The .github-ci.yml will then look something like:


name: Docker Image CI

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - name: checkout
      uses: actions/checkout@v2
    - name: Set up QEMU
      uses: docker/setup-qemu-action@v1
    - name: Set up Docker Buildx
      uses: docker/setup-buildx-action@v1
    - name: Login to ghcr.io
      uses: docker/login-action@v1
      with:
        registry: ghcr.io
        username: "<username>"
        password: ${{ secrets.PAT }}
    - name: 'Build and push images'
      uses: docker/build-push-action@v2
      with:
        file: ./Dockerfile
        context: .
        tags: ghcr.io/robbarnsley/<image>:<tag>
        push: true
        platforms: linux/amd64,linux/arm64  

Top