Hi,
I’m trying to build a multi-platform Docker image based on elixir:1.17-otp-27
. However, I’ve encountered an issue: the jason
library fails to compile on arm64
because my host machine is running on amd64
architecture. I’ve also tried building the image on an arm64
machine, but then the build step for amd64
fails.
Does anyone have any suggestions on how to resolve this issue? I prefer not to create separate image tags, as the elixir:1.17-otp-27
base image already seems to supports both architectures.
Steps to reproduce:
- Create new project:
mix new myapp
- Add
jason
as dependency in themix.exs
file:{:jason, "~> 1.4"}
- Create Dockerfile with the following contents:
FROM elixir:1.17-otp-27
WORKDIR /app
COPY . .
RUN MIX_ENV=prod mix deps.get
RUN MIX_ENV=prod mix compile
RUN MIX_ENV=prod mix release
- Build the image:
docker buildx build --platform linux/amd64,linux/arm64 -t myapp_test .
This is the output:
=> ERROR [linux/arm64 5/6] RUN MIX_ENV=prod mix compile 21.1s
------
> [linux/arm64 5/6] RUN MIX_ENV=prod mix compile:
6.777 ==> jason
6.779 Compiling 10 files (.ex)
17.80 Compiling lib/encode.ex (it's taking more than 10s)
19.47 Compiling lib/decoder.ex (it's taking more than 10s)
20.03 Generated jason app
20.07 could not compile dependency :jason, "mix compile" failed. Errors may have been logged above. You can recompile this dependency with "mix deps.compile jason --force", update it with "mix deps.update jason" or clean it with "mix deps.clean jason"
20.84 Segmentation fault (core dumped)
------
WARNING: No output specified with docker-container driver. Build result will only remain in the build cache. To push result image into registry use --push or to load image into docker use --load
Dockerfile:9
--------------------
7 |
8 | RUN MIX_ENV=prod mix deps.get
9 | >>> RUN MIX_ENV=prod mix compile
10 | RUN MIX_ENV=prod mix release
--------------------
ERROR: failed to solve: process "/bin/sh -c MIX_ENV=prod mix compile" did not complete successfully: exit code: 139
Is there anything else I could do to build the same tag for both architectures? Thanks in advance