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…

Where Next?

Popular in Questions Top

jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
makeitrein
Hey all, just started picking up Elixir last week and am writing a scraper as a learning project. Baby step #1 is extracting the number ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Other popular topics Top

srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
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
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
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
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

We're in Beta

About us Mission Statement