Bcrypt failing when running an elixir app inside Dokcer

I have the following dockerfile for an elixir app.

FROM elixir:1.8.1-alpine as builder
RUN apk update && \
  apk add git make alpine-sdk
COPY . .

RUN mix local.hex --force && \
  mix local.rebar --force

ENV MIX_ENV=prod
RUN mix deps.get && \
  mix compile
RUN mix release

FROM alpine:latest
ENV REPLACE_OS_VARS=true
RUN apk --no-cache add ca-certificates bash openssl
COPY --from=builder _build/prod/rel/app/releases/0.0.1/app.tar.gz .
RUN tar xzvf app.tar.gz && rm -rf app.tar.gz
CMD ["bin/app", "console" ]

Docker build is working fine however when I try to run the image I get the following error
{"Kernel pid terminated",application_controller,"{application_start_failure,kernel,{{shutdown,{failed_to_start_child,kernel_safe_sup,{on_load_function_failed,'Elixir.Bcrypt.Base'}}},{kernel,start,[normal,[]]}}}"}

Thanks

Are deps and _build part of your .dockerignore or are they copied into the container?

If they get copied into the container, then :bcrypt_elixirs NIFs won’t get recompiled and those compiled for your host system will get compiled into the release, which again can not work with the libmusl based alpine linux, as your host probably links against libc.

8 Likes

Thanks that solved the issue. I am running OSX and both the folders were getting copied.

1 Like

Faced this same issue. After adding both deps and _build to .docker-ignore, the problem was solved. Thanks!

1 Like