4

I'm trying to build a dockerfile on my mac M1 (arm64) in two ways (important part of dockerfile below):

FROM erlang:24

# elixir expects utf8.
ENV ELIXIR_VERSION="v1.12.2" \
    LANG=C.UTF-8

RUN set -xe \
    && ELIXIR_DOWNLOAD_URL="https://github.com/elixir-lang/elixir/archive/${ELIXIR_VERSION}.tar.gz" \
    && ELIXIR_DOWNLOAD_SHA256="701006d1279225fc42f15c8d3f39906db127ddcc95373d34d8d160993356b15c" \
    && curl -fSL -o elixir-src.tar.gz $ELIXIR_DOWNLOAD_URL \
    && echo "$ELIXIR_DOWNLOAD_SHA256  elixir-src.tar.gz" | sha256sum -c - \
    && mkdir -p /usr/local/src/elixir \
    && tar -xzC /usr/local/src/elixir --strip-components=1 -f elixir-src.tar.gz \
    && rm elixir-src.tar.gz \
    && cd /usr/local/src/elixir \
    && make install clean \
    && find /usr/local/src/elixir/ -type f -not -regex "/usr/local/src/elixir/lib/[^\/]*/lib.*" -exec rm -rf {} + \
    && find /usr/local/src/elixir/ -type d -depth -empty -delete

.
.
.

# docker compose
RUN COMPOSE_URL="https://circle-downloads.s3.amazonaws.com/circleci-images/cache/linux-amd64/docker-compose-latest" \
  && curl --silent --show-error --location --fail --retry 3 --output /usr/bin/docker-compose $COMPOSE_URL \
  && chmod +x /usr/bin/docker-compose \
  && docker-compose version

.
.
.
  1. using docker build -t test .

Since I'm trying to build amd64 (docker compose part) image on arm64 chip. I'm getting this error:

> [ 8/25] RUN COMPOSE_URL="https://circle-downloads.s3.amazonaws.com/circleci-images/cache/linux-amd64/docker-compose-latest"   && curl --silent --show-error --location --fail --retry 3 --output /usr/bin/docker-compose $COMPOSE_URL      && chmod +x /usr/bin/docker-compose          && docker-compose version:
#11 2.768 /lib64/ld-linux-x86-64.so.2: No such file or directory
------
Dockerfile:68
--------------------
  67 |     # docker compose
  68 | >>>  RUN COMPOSE_URL="https://circle-downloads.s3.amazonaws.com/circleci-images/cache/linux-amd64/docker-compose-latest" \
  69 | >>>       && curl --silent --show-error --location --fail --retry 3 --output /usr/bin/docker-compose $COMPOSE_URL \
  70 | >>>       && chmod +x /usr/bin/docker-compose \
  71 | >>>       && docker-compose version
  72 |
--------------------
error: failed to solve: process "/bin/sh -c COMPOSE_URL=\"https://circle-downloads.s3.amazonaws.com/circleci-images/cache/linux-amd64/docker-compose-latest\" \t && curl --silent --show-error --location --fail --retry 3 --output /usr/bin/docker-compose $COMPOSE_URL \t && chmod +x /usr/bin/docker-compose \t && docker-compose version" did not complete successfully: exit code: 255
  1. Using docker buildx build --platform linux/amd64 -t test .

This should resolve my problems with incompatibility and build the image using qemu emulator. But what I'm getting is rather related to the elixir (1. part of the dockerfile) or qemu itself.

The dockerfile part of elixir should be compatible with both chips and I assume it's qemu. Here is the error massage:

> [ 2/25] RUN set -xe  && ELIXIR_DOWNLOAD_URL="https://github.com/elixir-lang/elixir/archive/v1.12.2.tar.gz"   && ELIXIR_DOWNLOAD_SHA256="701006d1279225fc42f15c8d3f39906db127ddcc95373d34d8d160993356b15c"         && curl -fSL -o elixir-src.tar.gz $ELIXIR_DOWNLOAD_URL       && echo "$ELIXIR_DOWNLOAD_SHA256  elixir-src.tar.gz" | sha256sum -c -   && mkdir -p /usr/local/src/elixir       && tar -xzC /usr/local/src/elixir --strip-components=1 -f elixir-src.tar.gz  && rm elixir-src.tar.gz         && cd /usr/local/src/elixir     && make install clean        && find /usr/local/src/elixir/ -type f -not -regex "/usr/local/src/elixir/lib/[^\/]*/lib.*" -exec rm -rf {} +        && 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 | >>> RUN set -xe \
   8 | >>>      && ELIXIR_DOWNLOAD_URL="https://github.com/elixir-lang/elixir/archive/${ELIXIR_VERSION}.tar.gz" \
   9 | >>>      && ELIXIR_DOWNLOAD_SHA256="701006d1279225fc42f15c8d3f39906db127ddcc95373d34d8d160993356b15c" \
  10 | >>>      && curl -fSL -o elixir-src.tar.gz $ELIXIR_DOWNLOAD_URL \
  11 | >>>      && echo "$ELIXIR_DOWNLOAD_SHA256  elixir-src.tar.gz" | sha256sum -c - \
  12 | >>>      && mkdir -p /usr/local/src/elixir \
  13 | >>>      && tar -xzC /usr/local/src/elixir --strip-components=1 -f elixir-src.tar.gz \
  14 | >>>      && rm elixir-src.tar.gz \
  15 | >>>      && cd /usr/local/src/elixir \
  16 | >>>      && make install clean \
  17 | >>>      && find /usr/local/src/elixir/ -type f -not -regex "/usr/local/src/elixir/lib/[^\/]*/lib.*" -exec rm -rf {} + \
  18 | >>>      && find /usr/local/src/elixir/ -type d -depth -empty -delete
  19 |
--------------------
error: failed to solve: process "/bin/sh -c set -xe \t&& ELIXIR_DOWNLOAD_URL=\"https://github.com/elixir-lang/elixir/archive/${ELIXIR_VERSION}.tar.gz\" \t&& ELIXIR_DOWNLOAD_SHA256=\"701006d1279225fc42f15c8d3f39906db127ddcc95373d34d8d160993356b15c\" \t&& curl -fSL -o elixir-src.tar.gz $ELIXIR_DOWNLOAD_URL \t&& echo \"$ELIXIR_DOWNLOAD_SHA256  elixir-src.tar.gz\" | sha256sum -c - \t&& mkdir -p /usr/local/src/elixir \t&& tar -xzC /usr/local/src/elixir --strip-components=1 -f elixir-src.tar.gz \t&& rm elixir-src.tar.gz \t&& cd /usr/local/src/elixir \t&& make install clean \t&& find /usr/local/src/elixir/ -type f -not -regex \"/usr/local/src/elixir/lib/[^\\/]*/lib.*\" -exec rm -rf {} + \t&& find /usr/local/src/elixir/ -type d -depth -empty -delete" did not complete successfully: exit code: 2

Anyhow, I've tried building the image using rosetta but nothing helps. The image built fine on my linux amd64 machine though.

Here are related issues I've found but didn't help me much:
1. way of building
2. way of building

I hope I've provided enough information, if not ask me - thanks for help.

akad
  • 31
  • 1
  • 3

2 Answers2

0

I have tried different ways of building amd64 docker images on m1, and find the most stable way is:

Dharman
  • 30,962
  • 25
  • 85
  • 135
Bill
  • 63
  • 5
0

I suggest you to go with erlang:23 - because erlang:24 added JIT and qemu very much don't like it. Alternative - find erlang:24 version with disabled JIT

thousandsofthem
  • 1,355
  • 10
  • 9