sergio-ocon

sergio-ocon

Arm64 Dockerfile failing: ERROR [builder 6/17] RUN mix deps.get --only prod

Hi,

I am trying to build a multiple architecture image using Docker build.

> docker build -t chargio/liveview_counter --push --platform linux/arm64  .

I get an error (139) running this
> [+] Building 7.3s (16/28)                                                                                                                                                                                                                                                                                                                              docker:desktop-linux
>  => [internal] load .dockerignore                                                                                                                                                                                                                                                                                                                                      0.0s
>  => => transferring context: 1.35kB                                                                                                                                                                                                                                                                                                                                    0.0s
>  => [internal] load build definition from Dockerfile                                                                                                                                                                                                                                                                                                                   0.0s
>  => => transferring dockerfile: 2.54kB                                                                                                                                                                                                                                                                                                                                 0.0s
>  => [internal] load metadata for docker.io/library/debian:bookworm-20230612-slim                                                                                                                                                                                                                                                                                       0.9s
>  => [internal] load metadata for docker.io/hexpm/elixir:1.15.3-erlang-26.0.2-debian-bookworm-20230612-slim                                                                                                                                                                                                                                                             1.0s
>  => [builder  1/17] FROM docker.io/hexpm/elixir:1.15.3-erlang-26.0.2-debian-bookworm-20230612-slim@sha256:9fdcffc63a03bf77bf437510634ee7ad182135fc246283986c58fd8686c89326                                                                                                                                                                                             0.0s
>  => => resolve docker.io/hexpm/elixir:1.15.3-erlang-26.0.2-debian-bookworm-20230612-slim@sha256:9fdcffc63a03bf77bf437510634ee7ad182135fc246283986c58fd8686c89326                                                                                                                                                                                                       0.0s
>  => [internal] load build context                                                                                                                                                                                                                                                                                                                                      0.1s
>  => => transferring context: 73.36kB                                                                                                                                                                                                                                                                                                                                   0.1s
>  => [deploy 1/6] FROM docker.io/library/debian:bookworm-20230612-slim@sha256:d8f9d38c21495b04d1cca99805fbb383856e19794265684019bf193c3b7d67f9                                                                                                                                                                                                                          0.0s
>  => => resolve docker.io/library/debian:bookworm-20230612-slim@sha256:d8f9d38c21495b04d1cca99805fbb383856e19794265684019bf193c3b7d67f9                                                                                                                                                                                                                                 0.0s
>  => CACHED [deploy 2/6] RUN apt-get update -y && apt-get install -y libstdc++6 openssl libncurses5 locales   && apt-get clean && rm -f /var/lib/apt/lists/*_*                                                                                                                                                                                                          0.0s
>  => CACHED [deploy 3/6] RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen                                                                                                                                                                                                                                                                               0.0s
>  => CACHED [deploy 4/6] WORKDIR /app                                                                                                                                                                                                                                                                                                                                   0.0s
>  => CACHED [deploy 5/6] RUN chown nobody /app                                                                                                                                                                                                                                                                                                                          0.0s
>  => CACHED [builder  2/17] RUN apt-get update -y && apt-get install -y build-essential git     && apt-get clean && rm -f /var/lib/apt/lists/*_*                                                                                                                                                                                                                        0.0s
>  => CACHED [builder  3/17] WORKDIR /app                                                                                                                                                                                                                                                                                                                                0.0s
>  => CACHED [builder  4/17] RUN mix local.hex --force &&     mix local.rebar --force                                                                                                                                                                                                                                                                                    0.0s
>  => CACHED [builder  5/17] COPY mix.exs mix.lock ./                                                                                                                                                                                                                                                                                                                    0.0s
>  => ERROR [builder  6/17] RUN mix deps.get --only prod                                                                                                                                                                                                                                                                                                                 6.1s
> ------
>  > [builder  6/17] RUN mix deps.get --only prod:
> 6.023 qemu: uncaught target signal 11 (Segmentation fault) - core dumped
> 6.036 Segmentation fault
> ------
> Dockerfile:39
> --------------------
>   37 |     # install mix dependencies
>   38 |     COPY mix.exs mix.lock ./
>   39 | >>> RUN mix deps.get --only $MIX_ENV
>   40 |     RUN mkdir config
>   41 |
> --------------------
> ERROR: failed to solve: process "/bin/sh -c mix deps.get --only $MIX_ENV" did not complete successfully: exit code: 139

Blockquote

The same works great when using amd64.

I am using the Dockerfile generated by mix release --docker. And I’ve changed the debian version several times to use ‘bullseye’ - the default, ‘buster’, and ‘bookworm’, with the same result.

Do you know if there is some problem with the arm64 version of the image?

Marked As Solved

cschmatzler

cschmatzler

Add ENV ERL_FLAGS="+JPperf true" to your Dockerfile.

Also Liked

garazdawi

garazdawi

Erlang Core Team

I don’t need the JPperf parameter to make it run locally. What does it do? Why is not there by default? The documentation states that it provides profiling, and I am not sure why is needed in this case or what it changes to make the container work.

+JPperf true enables profiling, but it also changes the native code generation to use single page mapping instead of dual. As of Erlang/OTP 26 you can force usage of single page mapping by using +JMsingle true. Using dual page mapping is a security measure agaist possible expoits of bugs in in the JIT, so you normally want this, but as @sucipto sais, qemu has bugs when running using dual mapping so you need to disable it there. From what I can tell, QEMU 8.1 or later should have the bug fixed.

sergio-ocon

sergio-ocon

This made the trick. Now it is running and my image is published.

My Dockerfile:

# Find eligible builder and runner images on Docker Hub. We use Ubuntu/Debian
# instead of Alpine to avoid DNS resolution issues in production.
#
# https://hub.docker.com/r/hexpm/elixir/tags?page=1&name=ubuntu
# https://hub.docker.com/_/ubuntu?tab=tags
#
# This file is based on these images:
#
#   - https://hub.docker.com/r/hexpm/elixir/tags - for the build image
#   - https://hub.docker.com/_/debian?tab=tags&page=1&name=bullseye-20230612-slim - for the release image
#   - https://pkgs.org/ - resource for finding needed packages
#   - Ex: hexpm/elixir:1.15.3-erlang-26.0.2-debian-bullseye-20230612-slim
#
ARG ELIXIR_VERSION=1.15.4
ARG OTP_VERSION=26.0.2
ARG DEBIAN_VERSION=bookworm-20230612-slim

ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}"
ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}"

FROM ${BUILDER_IMAGE} as builder

# install build dependencies
RUN apt-get update -y && apt-get install -y build-essential git \
    && apt-get clean && rm -f /var/lib/apt/lists/*_*

# prepare build dir
WORKDIR /app

# install hex + rebar
RUN mix local.hex --force && \
    mix local.rebar --force

# set build ENV
ENV MIX_ENV="prod"
ENV ERL_FLAGS="+JPperf true"

# install mix dependencies
COPY mix.exs mix.lock ./
RUN mix deps.get --only $MIX_ENV
RUN mkdir config

# copy compile-time config files before we compile dependencies
# to ensure any relevant config change will trigger the dependencies
# to be re-compiled.
COPY config/config.exs config/${MIX_ENV}.exs config/
RUN mix deps.compile

COPY priv priv

COPY lib lib

COPY assets assets

# compile assets
RUN mix assets.deploy

# Compile the release
RUN mix compile

# Changes to config/runtime.exs don't require recompiling the code
COPY config/runtime.exs config/

COPY rel rel
RUN mix release

# start a new build stage so that the final image will only contain
# the compiled release and other runtime necessities
FROM ${RUNNER_IMAGE} as deploy

RUN apt-get update -y && apt-get install -y libstdc++6 openssl libncurses5 locales \
  && apt-get clean && rm -f /var/lib/apt/lists/*_*

# Set the locale
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen

ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8

WORKDIR "/app"
RUN chown nobody /app

# set runner ENV
ENV MIX_ENV="prod"

# Only copy the final release from the build stage
COPY --from=builder --chown=nobody:root /app/_build/${MIX_ENV}/rel/live_view_counter ./

USER nobody

CMD ["/app/bin/server"]

There is bug in Docker that prevents export of images to work if you are not using the base image too in the same command, so defining the platform as linux/arm64 on its own fails, you need to define both local (amd64) and the cross one (arm64)

% docker build -t chargio/liveview_counter --push  --platform linux/amd64,linux/arm64  .

Where Next?

Popular in Questions Top

LegitStack
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it. I’m very interested in Elixir,...
New
Kagamiiiii
Student & New to elixir. Nice language. I want to convert a english character, e.g. “a”, which is stored in a variable, to it’s asci...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
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
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
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
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
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
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New

Other popular topics Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
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
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
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
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
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New

We're in Beta

About us Mission Statement