Building ARM Images with Docker Buildx

Using buildx from Docker makes it super easy building images for multiple architectures.

I will be building a fluent-bit docker image for ARMv7 on a AMD64 platform.

Install Buildx

First installing buildx on our build server:

$ sudo apt install qemu-user -y
$ wget https://github.com/docker/buildx/releases/download/v0.4.2/buildx-v0.4.2.linux-amd64
$ mkdir ~/.docker/cli-plugins
$ mv buildx-v0.4.2.linux-amd64 .docker/cli-plugins/docker-buildx
$ chmod a+x ~/.docker/cli-plugins/docker-buildx

Making sure we can use the binary:

$ docker buildx

Usage:    docker buildx [OPTIONS] COMMAND  

Create a Build Instance

Create a new build instance which we will be using:

$ docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
$ docker buildx create --name newbuilder
$ docker buildx use newbuilder
$ docker buildx inspect --bootstrap

Build for ARM

In this example we will be building a docker image for armv7 of the loki fluent-bit plugin.

Get the source:

$ git clone https://github.com/grafana/loki

Login to your docker registry:

$ docker login

Then build using the --platform linux/arm/v7 flag:

$ docker buildx build -f cmd/fluent-bit/Dockerfile --push --platform linux/arm/v7  --tag pistacks/fluent-bit-plugin-loki:armv7-latest .

Once everything goes according to plan you should have an image for armv7 in your docker registry available.

Resources