Introduction
One sometimes needs to build docker images on a system and run them on another system
Step 1 : Know your system
On the target system one has to find the current arch, with
1
uname -m
in my case my target system is aarch64
I started diving because of the following error with docker run
0.498 exec /bin/sh: exec format error
which meant that i was using the wrong type of binary
Step2 : prepare the source system
QEMU is the best system to run different processors archs: to leverage that with docker, one has to install the target emu and the user static links, as described in here
1
apt install qemu-system-aarch64
and
1
apt install qemu-user-static
Step 3 : run the build
to run the build, normally run with --platform linux/aarch64
(more doc here)
1
docker build --platform linux/amd64 -f <path-to>/Dockerfile . -t <repo>/app/:tag
do not forget the .
for the context
there, otherwise you will get
ERROR: “docker buildx build” requires exactly 1 argument. See ‘docker buildx build –help’.
Usage: docker buildx build [OPTIONS] PATH URL - Start a build
Step 4 : run the image
to run the build, normally run with --platform linux/aarch64
1
docker run --platform linux/aarch64 --rm -ti <repo>/app/:tag
this will execute with said emulator.