Docker and Distillery
Hi,
I am trying to deploy my Distillery package in a Docker container.
My Docker file is like this:
FROM bitwalker/alpine-erlang:latest
# Maintainers
MAINTAINER XXX [email protected]
# Exposes this port from the docker container to the host machine
EXPOSE 4000
# Install other stable dependencies that don't change often
ENV TERM=xterm \
MIX_ENV=prod \
REPLACE_OS_VARS=true \
APP_NAME=app-name \
APP_VERSION=0.1.0
RUN mkdir /app
ADD . /app
WORKDIR /app/app-name/bin
CMD ["/app/app-name/bin/app-name", "foreground"]
The image is created and when I run I receive the following error:
xec: /app/stone_merchant_monitor/erts-8.0/bin/erlexec -noshell -noinput +Bd -boot /app/stone_merchant_monitor/releases/0.1.0/stone_merchant_monitor -mode embedded -config /app/stone_merchant_monitor/releases/0.1.0/sys.config -boot_var ERTS_LIB_DIR /app/stone_merchant_monitor/erts-8.0/../lib -args_file /app/stone_merchant_monitor/releases/0.1.0/vm.args -env ERL_LIBS /app/stone_merchant_monitor/lib -pa /app/stone_merchant_monitor/lib/stone_merchant_monitor-0.1.0/consolidated -extra -- foreground Root: /app/stone_merchant_monitor /app/stone_merchant_monitor/releases/0.1.0/stone_merchant_monitor.sh: line 552: ## /app/stone_merchant_monitor/erts-8.0/bin/erlexec: not found
Can you help me. The application is runnig perfectly.
Thanks in adcance
The release must be built for the same architecture as your target environment. So if you are running an Alpine container, the release must be built on Alpine.
Here's an example Dockerfile, based on apps I run at work:
FROM bitwalker/alpine-elixir:1.3.4
EXPOSE 4000
ENV PORT=4000 \
MIX_ENV=prod
COPY . .
RUN \
mix do deps.get, deps.compile && \
mix do compile, release --verbose --env=prod && \
mkdir -p /opt/myapp/log && \
cp rel/myapp/releases/0.1.0/myapp.tar.gz /opt/myapp/ && \
cd /opt/myapp && \
tar -xzf myapp.tar.gz && \
rm myapp.tar.gz && \
rm -rf /opt/app/* && \
chmod -R 777 /opt/app && \
chmod -R 777 /opt/myapp
WORKDIR /opt/myapp
CMD ./bin/myapp foreground
If you export ERTS from an Alpine container, you can build your release outside of Docker, and then mount the release into it. You can also download/build/install Elixir + the release, then remove all the build/install artifacts after copying the release to it's destination directory. The former is fine, but if you need to compile NIFs, you'll need a cross-compilation toolchain for those, which can get hairy if you aren't familiar with how to set that up. The downside of the latter is that it's super inefficient. The alpine-elixir image does have Elixir installed in it, so that part is a bit redundant, but I've found that the extra weight (which isn't much tbh) is worth the simplicity and the faster image build times. YMMV
When building the container There is an error in the json Dependency. This does not occur when I get or compile in my Red Hat Studio. It generates and the application runs properly.
I have already tried mix deps.compile json, update and clean
could not compile dependency :json, "mix compile" failed. You can recompile this dependency with "mix deps.compile json", update it with "mix deps.update json" or clean it with "mix deps.clean json"
20:15:39.606 [error] Native loading of /opt/app/_build/prod/lib/json/ebin/Elixir.JSON.beam failed: {:EXIT,
{:badarg,
[{:hipe_bifs, :patch_call, [1077937026, 140607107223148, []], []},
{:hipe_unified_loader, :patch_call_insn, 3,
[file: 'hipe_unified_loader.erl', line: 520]},
{:hipe_unified_loader, :patch_bif_call_list, 4,
[file: 'hipe_unified_loader.erl', line: 505]},
{:hipe_unified_loader, :patch_call, 5,
[file: 'hipe_unified_loader.erl', line: 496]},
{:hipe_unified_loader, :patch, 5,
[file: 'hipe_unified_loader.erl', line: 471]},
{:hipe_unified_loader, :load_common, 5,
[file: 'hipe_unified_loader.erl', line: 240]},
{:hipe_unified_loader, :load_native_code, 3,
[file: 'hipe_unified_loader.erl', line: 111]},
{:code_server, :try_load_module_2, 6,
[file: 'code_server.erl', line: 1111]}]}}
Will I have to change my json package ?
Could you link me to the repo for your JSON dependency? I'd like to do some testing.