<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="296202" data-post-id="296202">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="sergio-ocon" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/sergio-ocon/120/27154_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  sergio-ocon
                      <span class="op-star" title="Thread Starter">
                        <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                      </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>This made the trick. Now it is running and my image is published.</p>
<p>My Dockerfile:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir"># 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&amp;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&amp;page=1&amp;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 &amp;&amp; apt-get install -y build-essential git \
    &amp;&amp; apt-get clean &amp;&amp; rm -f /var/lib/apt/lists/*_*

# prepare build dir
WORKDIR /app

# install hex + rebar
RUN mix local.hex --force &amp;&amp; \
    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 &amp;&amp; apt-get install -y libstdc++6 openssl libncurses5 locales \
  &amp;&amp; apt-get clean &amp;&amp; rm -f /var/lib/apt/lists/*_*

# Set the locale
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen &amp;&amp; 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"]

</code></pre>
<p>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)</p>
<pre data-code-wrap="zsh"><code class="lang-zsh">% docker build -t chargio/liveview_counter --push  --platform linux/amd64,linux/arm64  .
</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="296202" data-batch-url="/posts/batch_likers">
                        3
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/arm64-dockerfile-failing-error-builder-6-17-run-mix-deps-get-only-prod/57317/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-296202" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="296202"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-most-liked cat-most-liked" title="One of the top 2 liked posts in this thread!"></div>
  </section>
</div>
    <div class="postbit" id="346429" data-post-id="346429">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="sergio-ocon" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/sergio-ocon/120/27154_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  sergio-ocon
                      <span class="op-star" title="Thread Starter">
                        <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                      </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="sergio-ocon" data-post="12" data-topic="57317">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/sergio-ocon/48/27154_2.png" class="avatar"> sergio-ocon:</div>
<blockquote>
<p><code>ENV ERL_FLAGS="+JPperf true"</code></p>
</blockquote>
</aside>
<p>One year later and the problem is still there. If I cross-compile using Github actions, the build fails when I don’t add JPperf true.</p>
<p>The logs shows this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">#19 16.54 Error while loading project :thousand_island at /app/deps/thousand_island
#19 16.57 {error,badarg,[{ets,lookup_element,[elixir_modules,'Elixir.Telemetry.Metrics',2],[{error_info,#{cause=&gt;badkey,module=&gt;erl_stdlib_errors}}]},{elixir_module,data_tables,1,[{file,"src/elixir_module.erl"},{line,27}]},{'Elixir.Kernel.Typespec',deftypespec,6,[{file,"lib/kernel/typespec.ex"},{line,136}]},{'Elixir.Inspect.PID',module_info,0,[]},{'Elixir.Exception',format_banner,3,[{file,"lib/exception.ex"},{line,148}]},{'Elixir.Kernel.CLI',format_error,3,[{file,"lib/kernel/cli.ex"},{line,107}]},{'Elixir.Kernel.CLI',print_error,3,[{file,"lib/kernel/cli.ex"},{line,177}]},{'Elixir.Kernel.CLI',exec_fun,2,[{file,"lib/kernel/cli.ex"},{line,165}]}]}
#19 16.57 Runtime terminating during boot ({badarg,[{ets,lookup_element,[elixir_modules,'Elixir.Telemetry.Metrics',2],[{error_info,#{cause=&gt;badkey,module=&gt;erl_stdlib_errors}}]},{elixir_module,data_tables,1,[{file,"src/elixir_module.erl"},{line,27}]},{'Elixir.Kernel.Typespec',deftypespec,6,[{file,"lib/kernel/typespec.ex"},{line,136}]},{'Elixir.Inspect.PID',module_info,0,[]},{'Elixir.Exception',format_banner,3,[{file,"lib/exception.ex"},{line,148}]},{'Elixir.Kernel.CLI',format_error,3,[{file,"lib/kernel/cli.ex"},{line,107}]},{'Elixir.Kernel.CLI',print_error,3,[{file,"lib/kernel/cli.ex"},{line,177}]},{'Elixir.Kernel.CLI',exec_fun,2,[{file,"lib/kernel/cli.ex"},{line,165}]}]})
#19 16.59
#19 16.59 Crash dump is being written to: erl_crash.dump...done
#19 ERROR: process "/bin/sh -c mix deps.compile" did not complete successfully: exit code: 1
</code></pre>
<p>My Dockerfile (updated and tested so it works):</p>
<pre data-code-wrap="elixir"><code class="lang-elixir"># 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&amp;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&amp;page=1&amp;name=bullseye-20241016-slim - for the release image
#   - https://pkgs.org/ - resource for finding needed packages
#   - Ex: hexpm/elixir:1.17.3-erlang-27.1.2-debian-bullseye-20241016-slim
#
ARG ELIXIR_VERSION=1.17.3
ARG OTP_VERSION=27.1.2
ARG DEBIAN_VERSION=bullseye-20241016-slim

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

FROM ${BUILDER_IMAGE} AS builder

ENV SRC_CODE="."

# Setting up locale so it does not complain about misconfigured latin1
ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8
ENV CODE=/app

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

# prepare build dir
WORKDIR ${CODE}

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

# set build ENV
ENV MIX_ENV="prod"
# Add JPperf as workaround for the failure on building the code in Github actions
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 --path /app_release

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

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

ARG MIX_ENV=prod

WORKDIR /deploy/
ENV HOME=/deploy
ENV MIX_ENV=${MIX_ENV}

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

# # Copying source code to the destination
COPY --from=builder --chown=nobody:root /app_release/ ./


# # This will be updated to a random user
USER nobody
EXPOSE 4000
# If using an environment that doesn't automatically reap zombie processes, it is
# advised to add an init process such as tini via `apt-get install`
# above and adding an entrypoint. See https://github.com/krallin/tini for details
# ENTRYPOINT ["/tini", "--"]

CMD ["/deploy/bin/server"]
</code></pre>
<p>I did some changes to the Dockerfile to make it better:</p>
<ul>
<li>I create the release in an specific path. That allows to make everything generic as it does not depend on the version or name of the app.</li>
<li>I execute it using server, exposing the port 4000, instead of application. It is an alias and works better</li>
</ul>
<p>My question: 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.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="346429" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/arm64-dockerfile-failing-error-builder-6-17-run-mix-deps-get-only-prod/57317/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-346429" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="346429"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #12"></div>
  </section>
</div>
    <div class="postbit" id="346433" data-post-id="346433">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="sucipto" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/sucipto/120/30405_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  sucipto
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Github action cross build for arm64 still use QEMU, and it’s QEMU bug:</p>
<aside class="quote" data-post="12" data-topic="43913">
  <div class="title">
    <div class="quote-controls"></div>
    <img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jhogberg/48/24176_2.png" class="avatar">
    <div class="quote-title__text-content">
      <a href="https://forum.elixirforum.com/t/building-elixir-erlang-linux-amd64-application-image-on-apple-silicon/43913/12" rel="nofollow">Building Elixir/Erlang linux/amd64 application image on Apple Silicon</a> <a class="badge-category__wrapper " href="/c/questions-help/questions/53" rel="nofollow"><span data-category-id="53" style="--category-badge-color: #C14BFB; --category-badge-text-color: #000000; --parent-category-badge-color: #C14BFB;" data-parent-category-id="171" data-drop-close="true" class="badge-category --style-square --has-parent" title="Elixir Questions / Help"><span class="badge-category__name">Questions</span></span></a>
    </div>
  </div>
  <blockquote>
    This is due to a bug in qemu, see <a href="https://gitlab.com/qemu-project/qemu/-/issues/1034" class="inline-onebox" rel="noopener nofollow ugc">Erlang/OTP 25 JIT on AArch64 fails in user mode emulation (#1034) · Issues · QEMU / QEMU · GitLab</a>. 
Older images most likely work because they don’t provide a C++ compiler capable of compiling the JIT, making it fall back to the interpreter.
  </blockquote>
</aside>

<p>maybe wait until github action support arm64 natively.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="346433" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/arm64-dockerfile-failing-error-builder-6-17-run-mix-deps-get-only-prod/57317/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-346433" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="346433"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #13"></div>
  </section>
</div>
    <div class="postbit" id="346442" data-post-id="346442">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="garazdawi" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/garazdawi/120/5853_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  garazdawi
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Erlang Core Team</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<blockquote>
<p>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.</p>
</blockquote>
<p><code>+JPperf true</code> 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 <a href="https://www.erlang.org/doc/apps/erts/erl_cmd.html#+JMsingle" rel="nofollow"><code>+JMsingle true</code></a>. Using dual page mapping is a security measure agaist possible expoits of bugs in in the JIT, so you normally want this, but as <a class="mention" href="/u/sucipto" rel="nofollow">@sucipto</a> 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.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="346442" data-batch-url="/posts/batch_likers">
                        6
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/arm64-dockerfile-failing-error-builder-6-17-run-mix-deps-get-only-prod/57317/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-346442" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="346442"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-most-liked cat-most-liked" title="One of the top 2 liked posts in this thread!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>