title: Building docker amd64 images on mac M1 chip
body: <p>I'm trying to build a dockerfile on my mac M1 (arm64) in two ways (important part of dockerfile below):</p>
  <pre><code>FROM erlang:24
  
  # elixir expects utf8.
  ENV ELIXIR_VERSION=&quot;v1.12.2&quot; \
      LANG=C.UTF-8
  
  RUN set -xe \
      &amp;&amp; ELIXIR_DOWNLOAD_URL=&quot;https://github.com/elixir-lang/elixir/archive/${ELIXIR_VERSION}.tar.gz&quot; \
      &amp;&amp; ELIXIR_DOWNLOAD_SHA256=&quot;701006d1279225fc42f15c8d3f39906db127ddcc95373d34d8d160993356b15c&quot; \
      &amp;&amp; curl -fSL -o elixir-src.tar.gz $ELIXIR_DOWNLOAD_URL \
      &amp;&amp; echo &quot;$ELIXIR_DOWNLOAD_SHA256  elixir-src.tar.gz&quot; | sha256sum -c - \
      &amp;&amp; mkdir -p /usr/local/src/elixir \
      &amp;&amp; tar -xzC /usr/local/src/elixir --strip-components=1 -f elixir-src.tar.gz \
      &amp;&amp; rm elixir-src.tar.gz \
      &amp;&amp; cd /usr/local/src/elixir \
      &amp;&amp; make install clean \
      &amp;&amp; find /usr/local/src/elixir/ -type f -not -regex &quot;/usr/local/src/elixir/lib/[^\/]*/lib.*&quot; -exec rm -rf {} + \
      &amp;&amp; find /usr/local/src/elixir/ -type d -depth -empty -delete
  
  .
  .
  .
  
  # docker compose
  RUN COMPOSE_URL=&quot;https://circle-downloads.s3.amazonaws.com/circleci-images/cache/linux-amd64/docker-compose-latest&quot; \
    &amp;&amp; curl --silent --show-error --location --fail --retry 3 --output /usr/bin/docker-compose $COMPOSE_URL \
    &amp;&amp; chmod +x /usr/bin/docker-compose \
    &amp;&amp; docker-compose version
  
  .
  .
  .
  </code></pre>
  <ol>
  <li>using <code>docker build -t test .</code></li>
  </ol>
  <p>Since I'm trying to build amd64 (docker compose part) image on arm64 chip. I'm getting this error:</p>
  <pre><code>&gt; [ 8/25] RUN COMPOSE_URL=&quot;https://circle-downloads.s3.amazonaws.com/circleci-images/cache/linux-amd64/docker-compose-latest&quot;   &amp;&amp; curl --silent --show-error --location --fail --retry 3 --output /usr/bin/docker-compose $COMPOSE_URL      &amp;&amp; chmod +x /usr/bin/docker-compose          &amp;&amp; docker-compose version:
  #11 2.768 /lib64/ld-linux-x86-64.so.2: No such file or directory
  ------
  Dockerfile:68
  --------------------
    67 |     # docker compose
    68 | &gt;&gt;&gt;  RUN COMPOSE_URL=&quot;https://circle-downloads.s3.amazonaws.com/circleci-images/cache/linux-amd64/docker-compose-latest&quot; \
    69 | &gt;&gt;&gt;       &amp;&amp; curl --silent --show-error --location --fail --retry 3 --output /usr/bin/docker-compose $COMPOSE_URL \
    70 | &gt;&gt;&gt;       &amp;&amp; chmod +x /usr/bin/docker-compose \
    71 | &gt;&gt;&gt;       &amp;&amp; docker-compose version
    72 |
  --------------------
  error: failed to solve: process &quot;/bin/sh -c COMPOSE_URL=\&quot;https://circle-downloads.s3.amazonaws.com/circleci-images/cache/linux-amd64/docker-compose-latest\&quot; \t &amp;&amp; curl --silent --show-error --location --fail --retry 3 --output /usr/bin/docker-compose $COMPOSE_URL \t &amp;&amp; chmod +x /usr/bin/docker-compose \t &amp;&amp; docker-compose version&quot; did not complete successfully: exit code: 255
  </code></pre>
  <ol start="2">
  <li>Using <code>docker buildx build --platform linux/amd64 -t test .</code></li>
  </ol>
  <p>This should resolve my problems with incompatibility and build the image using qemu emulator. But what I'm getting is rather related to the <a href="https://github.com/erlef/docker-elixir/blob/master/1.12/Dockerfile" rel="nofollow noreferrer">elixir (1. part of the dockerfile)</a> or qemu itself.</p>
  <p>The dockerfile part of elixir should be compatible with both chips and I assume it's qemu. Here is the error massage:</p>
  <pre><code>&gt; [ 2/25] RUN set -xe  &amp;&amp; ELIXIR_DOWNLOAD_URL=&quot;https://github.com/elixir-lang/elixir/archive/v1.12.2.tar.gz&quot;   &amp;&amp; ELIXIR_DOWNLOAD_SHA256=&quot;701006d1279225fc42f15c8d3f39906db127ddcc95373d34d8d160993356b15c&quot;         &amp;&amp; curl -fSL -o elixir-src.tar.gz $ELIXIR_DOWNLOAD_URL       &amp;&amp; echo &quot;$ELIXIR_DOWNLOAD_SHA256  elixir-src.tar.gz&quot; | sha256sum -c -   &amp;&amp; mkdir -p /usr/local/src/elixir       &amp;&amp; tar -xzC /usr/local/src/elixir --strip-components=1 -f elixir-src.tar.gz  &amp;&amp; rm elixir-src.tar.gz         &amp;&amp; cd /usr/local/src/elixir     &amp;&amp; make install clean        &amp;&amp; find /usr/local/src/elixir/ -type f -not -regex &quot;/usr/local/src/elixir/lib/[^\/]*/lib.*&quot; -exec rm -rf {} +        &amp;&amp; find /usr/local/src/elixir/ -type d -depth -empty -delete:
  #5 0.087 + ELIXIR_DOWNLOAD_URL=https://github.com/elixir-lang/elixir/archive/v1.12.2.tar.gz
  #5 0.087 + ELIXIR_DOWNLOAD_SHA256=701006d1279225fc42f15c8d3f39906db127ddcc95373d34d8d160993356b15c
  #5 0.088 + curl -fSL -o elixir-src.tar.gz https://github.com/elixir-lang/elixir/archive/v1.12.2.tar.gz
  #5 0.163   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
  #5 0.165                                  Dload  Upload   Total   Spent    Left  Speed
  100   127    0   127    0     0    243      0 --:--:-- --:--:-- --:--:--   246
  100 2402k  100 2402k    0     0  1331k      0  0:00:01  0:00:01 --:--:-- 1982k
  #5 1.984 + echo 701006d1279225fc42f15c8d3f39906db127ddcc95373d34d8d160993356b15c  elixir-src.tar.gz
  #5 1.984 + sha256sum -c -
  #5 2.033 elixir-src.tar.gz: OK
  #5 2.035 + mkdir -p /usr/local/src/elixir
  #5 2.053 + tar -xzC /usr/local/src/elixir --strip-components=1 -f elixir-src.tar.gz
  #5 2.193 + rm elixir-src.tar.gz
  #5 2.209 + cd /usr/local/src/elixir
  #5 2.209 + make install clean
  #5 2.520 sys/unix/sys_signal_stack.c:269:sys_sigaltstack(): Internal error: Failed to set alternate signal stack
  #5 2.521 qemu: uncaught target signal 6 (Aborted) - core dumped
  #5 2.526 make: *** [Makefile:82: lib/elixir/src/elixir_parser.erl] Aborted
  ------
  Dockerfile:7
  --------------------
     6 |
     7 | &gt;&gt;&gt; RUN set -xe \
     8 | &gt;&gt;&gt;      &amp;&amp; ELIXIR_DOWNLOAD_URL=&quot;https://github.com/elixir-lang/elixir/archive/${ELIXIR_VERSION}.tar.gz&quot; \
     9 | &gt;&gt;&gt;      &amp;&amp; ELIXIR_DOWNLOAD_SHA256=&quot;701006d1279225fc42f15c8d3f39906db127ddcc95373d34d8d160993356b15c&quot; \
    10 | &gt;&gt;&gt;      &amp;&amp; curl -fSL -o elixir-src.tar.gz $ELIXIR_DOWNLOAD_URL \
    11 | &gt;&gt;&gt;      &amp;&amp; echo &quot;$ELIXIR_DOWNLOAD_SHA256  elixir-src.tar.gz&quot; | sha256sum -c - \
    12 | &gt;&gt;&gt;      &amp;&amp; mkdir -p /usr/local/src/elixir \
    13 | &gt;&gt;&gt;      &amp;&amp; tar -xzC /usr/local/src/elixir --strip-components=1 -f elixir-src.tar.gz \
    14 | &gt;&gt;&gt;      &amp;&amp; rm elixir-src.tar.gz \
    15 | &gt;&gt;&gt;      &amp;&amp; cd /usr/local/src/elixir \
    16 | &gt;&gt;&gt;      &amp;&amp; make install clean \
    17 | &gt;&gt;&gt;      &amp;&amp; find /usr/local/src/elixir/ -type f -not -regex &quot;/usr/local/src/elixir/lib/[^\/]*/lib.*&quot; -exec rm -rf {} + \
    18 | &gt;&gt;&gt;      &amp;&amp; find /usr/local/src/elixir/ -type d -depth -empty -delete
    19 |
  --------------------
  error: failed to solve: process &quot;/bin/sh -c set -xe \t&amp;&amp; ELIXIR_DOWNLOAD_URL=\&quot;https://github.com/elixir-lang/elixir/archive/${ELIXIR_VERSION}.tar.gz\&quot; \t&amp;&amp; ELIXIR_DOWNLOAD_SHA256=\&quot;701006d1279225fc42f15c8d3f39906db127ddcc95373d34d8d160993356b15c\&quot; \t&amp;&amp; curl -fSL -o elixir-src.tar.gz $ELIXIR_DOWNLOAD_URL \t&amp;&amp; echo \&quot;$ELIXIR_DOWNLOAD_SHA256  elixir-src.tar.gz\&quot; | sha256sum -c - \t&amp;&amp; mkdir -p /usr/local/src/elixir \t&amp;&amp; tar -xzC /usr/local/src/elixir --strip-components=1 -f elixir-src.tar.gz \t&amp;&amp; rm elixir-src.tar.gz \t&amp;&amp; cd /usr/local/src/elixir \t&amp;&amp; make install clean \t&amp;&amp; find /usr/local/src/elixir/ -type f -not -regex \&quot;/usr/local/src/elixir/lib/[^\\/]*/lib.*\&quot; -exec rm -rf {} + \t&amp;&amp; find /usr/local/src/elixir/ -type d -depth -empty -delete&quot; did not complete successfully: exit code: 2
  </code></pre>
  <p>Anyhow, I've tried building the image using rosetta but nothing helps. The image built fine on my linux amd64 machine though.</p>
  <p>Here are related issues I've found but didn't help me much: <br>
  <a href="https://www.google.com/search?q=qemu%3A%20uncaught%20target%20signal%206%20%28Aborted%29%20-%20core%20dumped&amp;ei=SXobYZapMYzdkwWsy5KICg&amp;oq=qemu%3A%20uncaught%20target%20signal%206%20%28Aborted%29%20-%20core%20dumped&amp;gs_lcp=Cgdnd3Mtd2l6EAMyBQgAEIAEMgUIABCABDoHCAAQRxCwA0oECEEYAFCA6gVYgOoFYP_sBWgEcAJ4AIABfYgBtQGSAQMxLjGYAQCgAQKgAQHIAQjAAQE&amp;sclient=gws-wiz&amp;ved=0ahUKEwjW8eK12LfyAhWM7qQKHaylBKEQ4dUDCA4&amp;uact=5" rel="nofollow noreferrer">1. way of building</a> <br>
  <a href="https://www.google.com/search?q=docker%20m1%20%2Flib64%2Fld-linux-x86-64.so.2%3A%20No%20such%20file%20or%20directory&amp;oq=docker%20m1%20%2Flib64%2Fld-linux-x86-64.so.2%3A%20No%20such%20file%20or%20directory&amp;aqs=chrome.0.69i59.4732j0j7&amp;sourceid=chrome&amp;ie=UTF-8" rel="nofollow noreferrer">2. way of building</a></p>
  <p>I hope I've provided enough information, if not ask me - thanks for help.</p>