I have a Raspberry Pi 4 on my LAN that has a bunch of containerized applications running, but unfortunately, Sonatype doesn't offer an ARM build of their Docker image Running it gives the following error:
exec user process caused "exec format error"
which is symptomatic of an architecture mismatch i.e. Docker has incorrectly pulled the x86_64 image, which won't run on an ARM processor.
However, one good soul has done the heavy lifting to create an ARM version, complete with pre-built images, but it's obviously a bit of security risk to just download and run images from unknown parties. Instructions are provided for building the image yourselfWhich allows you to review the Dockerfile, to see what's going into the image., but they're a little terse if you're not already familiar with the tools used, so this page explains things in a bit more detail.
Cross-building Docker images
Docker Buildx is a new engine used by Docker to build images, and while it was originally released as a plugin that had to be installed separately, it is now part of a standard Docker installRun docker buildx to see if you have it..
However, when I tried to use it on my Raspberry Pi, I got the following error:
Cannot autolaunch D-Bus without X11 $DISPLAY
which appears to be a Docker problem, caused by a dependency on a GUI-based credential helper The solution is to uninstall the golang-docker-credential-helpers packageI also got around this by logging in on another machine, and then copying the ~/.docker/config.json file over , but there is another way.
One of the features Docker Buildx offers is the ability to build images targeting different architectures, so all we have to do is build an ARM image on a PC, and then transfer that image to the Raspberry Pi and run it there.
First, we need to install QEMU binaries into the host kernel, which will allow other architectures to be emulated:
docker run --rm --privileged \ docker/binfmt:a7996909642ee92942dcd6cff44b9b95f08dad64
If you haven't already done so, create a builder, which is an isolated environment in which images can be built:
docker buildx create --name mybuilder
Then start the builder:
docker buildx use mybuilder docker buildx inspect --bootstrap
docker buildx build --pull \ --platform "linux/arm/v7" \ --tag "nexus3-armv7" \ --output "type=docker" \ .
This will take some time to run.
Transferring the Docker image to the Raspberry Pi
To transfer the image to the Raspberry Pi, just push it to a registryEither your own private registry, or Docker Hub. somewhere, and then pull it down on the Raspberry Pi.
Alternatively, you can save the image to a file:
docker image save -o nexus3-armv7.tar nexus3-armv7
and then copy the file to the Raspberry Pi and restore it there:
docker load -i nexus3-armv7.tar
|↵1||Which allows you to review the Dockerfile, to see what's going into the image.|
|↵2||Run docker buildx to see if you have it.|
|↵3||I also got around this by logging in on another machine, and then copying the ~/.docker/config.json file over|
|↵4||At the time of writing, a 64-bit Raspberry Pi OS is on the horizon, but mine are still 32-bit, so we target linux/arm/v7.|
|↵5||Either your own private registry, or Docker Hub.|