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.

 

Figure 1 - Buildx experimental functionality notes

Figure 1 – Buildx experimental functionality notes

 

Using this tool, I was able to prepare the Apache Karaf image for linux/arm64 and linux/arm/v7 which I then used on the Raspberry Pi 3 and 4.

 

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 2.0.4.0 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 2.3.6.1. The figure below shows the details of my Docker Desktop Edge installation.

 

Figure 2 - Docker Desktop Edge version details

Figure 2 – Docker Desktop Edge version details

 

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:

  1. verify that buildx is correctly installed;
  2. creation of the builder via buildx;
  3. clone of the Apache Karaf repository;
  4. 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).

 

 

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.

 

Figure 3 - Inspect the Apache Karaf Docker image

Figure 3 – Inspect the Apache Karaf Docker image

 

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.

 

Figure 4 - Apache Karaf 4.2.9 Docker image for ARM on Docker Hub

Figure 4 – Apache Karaf 4.2.9 Docker image for ARM on Docker Hub

 

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.

 

Antonio Musarra

I began my journey into the world of computing from an Olivetti M24 PC (http://it.wikipedia.org/wiki/Olivetti_M24) bought by my father for his work. Day after day, quickly taking control until … Now doing business consulting for projects in the enterprise application development using web-oriented technologies such as J2EE, Web Services, ESB, TIBCO, PHP.

You may also like...