Docker: How to create Apache Karaf images for ARM and ARM64
I recently published the article Raspberry Pi: How to run an Apache Karaf 4.2 Docker Container focused on installing Docker on Raspberry Pi and how to run an Apache Karaf container based on Docker amusarra/karaf:4.2.9 image.
In the course of this article we will see how to create the Apache Karaf Docker image for linux/arm and linux/arm64 architectures. The same method can be applied to multi-architecture Docker imaging for any type of application.
To effectively follow this short article, basic knowledge of Docker is recommended.
1. Our friend: Buildx
Thanks to the partnership between Docker and ARM (see Docker announced a partnership with Arm) announced in April 2019, today we are able to perform multi-architecture image builds, including ARM.
Thanks to Docker Buildx we can therefore create multi-architecture images for both ARM and x86 using Docker Desktop.
Docker Buildx is a Command Line Interface (CLI) plug-in that extends the docker command with full support of the functionality provided by the Moby BuildKit toolkit. It provides the same user experience as the standard build command but with many new features such as creating scoped builder instances and building on multiple nodes at the same time.
2. How to get Buildx
Docker Buildx is included in Docker 19.03 and is also bundled with the following versions of Docker Desktop. Note that you need to enable the Experimental Features option to use Docker Buildx.
- Docker Desktop Enterprise version 2.1.0.
- Docker Desktop Edge version 126.96.36.199 or later.
You can also download the latest buildx binary from Docker’s buildx repository.
I personally downloaded and installed Docker Desktop Edge for macOS version 188.8.131.52. The figure below shows the details of my Docker Desktop Edge installation.
Once Docker Desktop is installed and/or updated, we will have the buildx tool at our disposal, which will allow us to easily create multi-architecture Docker images.
3. How to create the Apache Karaf image
The Docker Hub repository of the Apache Karaf project provides the image for the linux/amd64 architecture only. Instead, my goal was to obtain an image for the two architectures linux/arm and linux/arm64, deriving from the fact that I needed to run an Apache Karaf Docker container in a Raspberry Pi environment, the latter mounts processors ARM, both 32bit and 64bit.
When feasible, I generally follow the approach which results in: write as little as possible, always extend.
The Apache Karaf project already provides the Docker image build process through a bash script, so I didn’t have to do anything other than extend the existing script so that it would consider using buildx to create multi-architecture images and modify the Dockerfile for the FROM directive to refer to a multi-architecture image.
What are the steps required to obtain an Apache Karaf Docker image for the linux/arm and linux/arm64 architectures?
The procedure is quite simple and consists of the following steps:
- verify that buildx is correctly installed;
- creation of the builder via buildx;
- clone of the Apache Karaf repository;
- run build.sh script to build Apache Karaf Docker image for ARM. The script also pushes to Docker Hub.
Below are shown all the commands needed to get the Apache Karaf Docker image version 4.2.9 (see parameter –from-release of the build.sh command) for ARM (linux/arm/v7) and ARM64 (linux/arm64). The platforms to be built can be specified via the –build-multi-platform parameter).
# Check Docker Buildx (get version)
$ docker buildx version
# Create a builder for Apache Karaf
$ docker buildx create --name karaf-builder \
--platform linux/arm64,linux/arm/v7,linux/amd64 \
# Clone the Apache Karaf Repository
$ git clone --depth 1 https://github.com/apache/karaf.git
$ cd karaf/assemblies/docker
# Run build the Docker Image for ARM and push
# the image amusarra/karaf:4.2.9-dev on Docker Hub
# account amusarra.
$ ./build.sh --from-release --karaf-version 4.2.9 \
--image-name amusarra/karaf:4.2.9-dev \
The image below shows the output of the buildx command for inspecting the image just created and pushed to Docker Hub. I highlighted the fact that this image is available for the two platforms linux/arm/v7 and linux/arm64.
Below you can see the sequence of all the steps that have been performed Build and Push Docker Apache Karaf image for ARM / ARM64 Architecture, as indicated in Console 1.
4. Conclusions and resources
We saw how easy it was to create the Apache Karaf Docker image for linux/arm and linux/arm64 architectures using the Docker buildx tool and the build script available directly on the Apache Karaf project’s GitHub repository.
In this article I took Apache Karaf as an example, obviously, buildx, it can be used to create multi-architecture Docker images for any application you want.
Following are a series of useful resources to deepen the subject matter.
- Docker Buildx
- Moby BuildKit
- Docker buildx repository
- Building Multi-Arch Images for Arm and x86 with Docker Desktop