anuaralfetahe

anuaralfetahe

Multi-platform docker image build fails

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 jasonas dependency in the mix.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 :slight_smile:

Marked As Solved

garazdawi

garazdawi

Erlang Core Team

Is it specifically jason? Does it work for other libraries?

There have been issues in the past with qemu and the Erlang JIT, though they usually manifest earlier. Try setting ERL_FLAGS="+JMsingle true" and see if that helps.

Also Liked

garazdawi

garazdawi

Erlang Core Team

It does not effect runtime if you only enable it during compilation. The flag disables some safeguards put in place that limits what an attacker can do if they find a vulnerability in the JIT.

dimitarvp

dimitarvp

A shot in the dark, maybe installing build-essential with the distro’s package manager could help? Though I don’t think jason has any native dependencies…

Last Post!

garazdawi

garazdawi

Erlang Core Team

It does not effect runtime if you only enable it during compilation. The flag disables some safeguards put in place that limits what an attacker can do if they find a vulnerability in the JIT.

Where Next?

Popular in Questions Top

nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New

Other popular topics Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 49084 226
New

We're in Beta

About us Mission Statement