title: How to install qemu emulator for arm in a docker container
body: <p>My goal is to build a <a href="https://docs.docker.com/buildx/working-with-buildx/" rel="nofollow noreferrer">Docker Build</a> image that can be used as a CI stage that's capable of building a multi-archtecture image.</p>
  <pre><code>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
  </code></pre>
  <p>^ builds the container I need, but does not include the emulator of <code>arm64</code>.  This means when I try to use it to build a multiarchitecture image via a command like <code>docker buildx build --platform=$SUPPORTED_ARCHITECTURES --build-arg PHP_VERSION=8.0.1 -t my-repo:latest .</code>, I get the error:</p>
  <pre><code>error: failed to solve: process &quot;/dev/.buildkit_qemu_emulator /bin/sh -c apt-get update &amp;&amp; apt-get -y install -q ....
  </code></pre>
  <p>The solution is to run <code>docker run --rm --privileged tonistiigi/binfmt --install arm64</code> as part of the CI steps, which uses the <code>buildx</code> container I previously built.  However, <strong>I'd <em>really</em> like to understand why the emulator cannot seem to be installed in the container</strong> by adding something like this to the Dockerfile:</p>
  <pre><code># Install arm emulator
  COPY --from=tonistiigi/binfmt /usr/bin/binfmt /usr/bin/binfmt
  RUN /usr/bin/binfmt --install arm64
  </code></pre>