Running amd64 docker image on arm64 - docker

I am trying to run a amd64 based docker image on my arm64 based host platform. However, when I try to do so (with docker run) I get the following error
Error:
standard_init_linux.go:219: exec user process caused: exec format error

I am afraid you still need to compile the code for arm64 architecture and build your own docker file, then docker run it.

Related

docker buildx takes longer time to build multi arch images - ARM64 and AMD64 than single arch

using docker buildx build --platform linux/arm64,linux/amd64 takes 5 times longer than
docker build .
I'm running the command using jenkins pipeline on a amd64 slave.
Is there any way to build the image faster?

docker buildx failed to build amd64 image in system with architecture arm64

I am trying to build a docker image with command
docker buildx build --platform=linux/amd64 -f .devcontainer/Dockerfile .
it fails with error ERROR: unexpected end of JSON input
however docker build and run does not fail
what could this error mean ?
Looks like this is just a syntax error when specifying the architecture.
It would need to be this instead:
docker buildx build --platform linux/amd64 ...

error: failed to solve: snapshot does not exist: not found

When running
docker buildx build --platform linux/arm64,linux/amd64,linux/arm/v7 -t my-project .
it fails with a very cryptic error message:
------
> [internal] load build context:
------
error: failed to solve: snapshot does not exist: not found
which I can't find in google.
This is on debian, I just switched from debian's docker.io for the docker-ce package to get buildx support.
This cryptic error is shown when using docker buildx with a buildx-capable docker command, but with the docker service still being the old non-buildx-capable one.
Manually restart the docker service with
service docker restart
(or similar, depending on your service system) and buildx will work just fine.

How to install qemu emulator for arm in a docker container

My goal is to build a Docker Build image that can be used as a CI stage that's capable of building a multi-archtecture image.
FROM public.ecr.aws/docker/library/docker:20.10.11-dind
# Add the buildx plugin to Docker
COPY --from=docker/buildx-bin:0.7.1 /buildx /usr/libexec/docker/cli-plugins/docker-buildx
# Create a buildx image builder that we'll then use within this container to build our multi-architecture images
RUN docker buildx create --platform linux/amd64,linux/arm64 --name=my-builder --use
^ builds the container I need, but does not include the emulator of arm64. This means when I try to use it to build a multiarchitecture image via a command like docker buildx build --platform=$SUPPORTED_ARCHITECTURES --build-arg PHP_VERSION=8.0.1 -t my-repo:latest ., I get the error:
error: failed to solve: process "/dev/.buildkit_qemu_emulator /bin/sh -c apt-get update && apt-get -y install -q ....
The solution is to run docker run --rm --privileged tonistiigi/binfmt --install arm64 as part of the CI steps, which uses the buildx container I previously built. However, I'd really like to understand why the emulator cannot seem to be installed in the container by adding something like this to the Dockerfile:
# Install arm emulator
COPY --from=tonistiigi/binfmt /usr/bin/binfmt /usr/bin/binfmt
RUN /usr/bin/binfmt --install arm64
I'd really like to understand why the emulator cannot seem to be installed in the container
Because when you perform a RUN command, the result is to capture the filesystem changes from that step, and save them to a new layer in your image. But the qemu setup command isn't really modifying the filesystem, it's modifying the host kernel, which is why it needs --privileged to run. You'll see evidence of those kernel changes in /proc/sys/fs/binfmt_misc/ on the host after configuring qemu. It's not possible to specify that flag as part of the container build, all steps run in the Dockerfile are unprivileged, without access to the host devices or the ability to alter the host kernel.
The standard practice in CI systems is to configure the host in advance, and then run the docker build. In GitHub Actions, that's done with the setup-qemu-action before running the build step.

Need docker to build docker?

I download the docker and want to compile it from the source code:
[root#localhost docker-1.5.0]# make
mkdir bundles
docker build -t "docker" .
/bin/sh: docker: command not found
make: *** [build] Error 127
Per my understanding, if I want to compile docker, I need to get a docker firstly. Is it right? If it is true, how does the first docker come?
yum or apt-get install docker-io will install the docker-io
then you build it from source and it replace the existing docker or set your path to point to the new docker.
You must have Docker to build Docker only because that's what the Docker guys thought would be the most convenient.
Of course, there is a way to compile the Docker source without having Docker installed on your machine; but then - you will have to have on your machine all the compilation tools and dependencies needed for the compilation.
So, the Docker team "dockerized" the compilation process. Namely, they used Docker itself, and what it is intended to do, also for the compilation of the Docker source.

Resources