Amazon Linux 2上的混合发行版

问题描述

目标:要能够运行凤凰,请在ec2实例中混合发行(此机器:https://hub.docker.com/_/amazonlinux/

问题:运行我的发行版会产生以下错误:

/my_app/erts-11.0.3/bin/beam.smp: /lib64/libtinfo.so.6: no version information available (required by /my_app/erts-11.0.3/bin/beam.smp)
2020-09-08 13:17:33.469328
    args: [load_failed,"Failed to load NIF library /my_app/lib/crypto-4.7/priv/lib/crypto: 'libcrypto.so.1.1: cannot open shared object file: No such file or directory'","OpenSSL might not    format:     label:  be installed on this system.\n"]
"Unable to load crypto library. Failed with error:~n\"~p,~s\"~n~s"
{error_logger,error_msg}

但是在每种情况下(openssl)我都安装了OpenSSL 1.0.2k-fips 26 Jan 2017

设置

我使用以下命令创建一个新的phoenix项目:

yes | mix phx.new my_app --no-webpack --no-ecto --no-dashboard --no-gettext
cd my_app

并取消注释config :my_app,MyAppWeb.Endpoint,server: true中的config/prod.secret.exs行以在运行应用程序时启动服务器。

我创建以下Dockerfile来构建我的项目:

FROM debian:buster

# Install essential build packages
RUN apt-get update 
RUN apt-get install -y wget git locales curl gnupg-agent

# Set locale
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
    dpkg-reconfigure --frontend=noninteractive locales && \
    update-locale LANG=en_US.UTF-8
ENV LANG en_US.UTF-8

ENV HOME=/opt/app

WORKDIR /opt/app

# Install erlang and elixir
RUN wget https://packages.erlang-solutions.com/erlang-solutions_2.0_all.deb
RUN dpkg -i erlang-solutions_2.0_all.deb
RUN apt-get update
RUN apt-get install -y esl-erlang
RUN apt-get install -y elixir

# Install hex and rebar
RUN mix do local.hex --force,local.rebar --force

# Install phoenix
RUN mix archive.install hex phx_new 1.5.4 --force

COPY mix.exs mix.lock ./
COPY config config
COPY priv priv
COPY lib lib

RUN mix deps.get

ENV SECRET_KEY_BASE='secretExampleQrzdplBPdbHHhr2bpELjiGVGVqmjvFl2JEXdkyla8l6+b2CCcvs'
ENV MIX_ENV=prod

RUN mix phx.digest
RUN mix compile
RUN mix release

CMD ["_build/prod/rel/my_app/bin/my_app","start"]

并使用以下图像构建图像:

docker build . -t my_app

我们可以通过以下方法检查一切是否按预期运行:

docker run -p 4000:4000 -i my_app:latest

并访问localhost:4000

我从构建的Docker容器复制_build/prod/rel/my_app目录(因为这就是我要转移到ec2实例的全部内容)。

# list all containers
docker container ls -a
# locate the container with image tag: my_app:latest. It should look like:
# f9c46df97e55        my_app:latest         "_build/prod/rel/my_…"
# note the container_id,and copy across the build release
docker cp f9c46df97e55:/opt/app/_build/prod/rel/my_app .

我们创建一个instance.Dockerfile来运行ec2实例的命令:

FROM amazonlinux:latest

COPY my_app my_app

CMD ["my_app/bin/my_app","start"]

并运行它:

docker build . -f instance.Dockerfile -t my_app_instance && docker run -p 4000:4000 -i my_app_instance:latest

此操作无法运行,并显示以下错误:

[load_failed,"Failed to 2020-09-08 13:27:49.980715
    args: load NIF library /my_app/lib/crypto-4.7/priv/lib/crypt    format:     label: 2020-09-08 13:27:49.981847 supervisor_report   o: 'libcrypto.so.1.1: cannot open shared object file: No such file or directory'","OpenSSL might not be installed on this system.\n"]
"Unable to load crypto library. Failed with error:~n\"~p,error_msg}

注意

我可以使用上面的debian:buster命令在docker build ... && docker run ...机器上复制错误,但是要使用此instance.Dockerfile

FROM debian:buster

RUN apt-get update 
RUN apt-get install -y locales

# Set locale
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
    dpkg-reconfigure --frontend=noninteractive locales && \
    update-locale LANG=en_US.UTF-8
ENV LANG en_US.UTF-8

COPY my_app my_app

CMD ["my_app/bin/my_app","start"]

并通过将RUN apt-get install -y locales更改为RUN apt-get install -y locales curl来纠正错误。

我在yum install curl机器上尝试过yum install opensslamazonlinux:latest,但是仍然遇到相同的错误。

问题

我应该在哪里取得进展?这似乎是一个erlang / otp要求问题,但以上内容几乎不是sscce,因此很难提出。

我一直在努力寻找apt-get curl软件包安装了什么加密货币或openssl库,从而导致错误得以解决。

任何指向特定论坛寻求帮助或下一步尝试的指针将不胜感激。

预先感谢您的帮助。

解决方法

感谢在@VenkatakumarSrinivasan的CentO上构建它的建议,

我设法使其在具有以下amazonlinux的{​​{1}}机器上运行。

构建发行版:

Dockerfile

运行版本:

FROM centos:7

RUN yum update -y
RUN yum clean -y all

RUN echo 'LC_ALL="en_US.UTF-8"' >> /etc/locale.conf
ENV LC_ALL="en_US.UTF-8"

RUN yum install -y epel-release
RUN yum install -y gcc gcc-c++ glibc-devel make ncurses-devel openssl-devel \
                   autoconf java-1.8.0-openjdk-devel git wget wxBase.x86_64

WORKDIR /opt

RUN wget http://packages.erlang-solutions.com/erlang-solutions-1.0-1.noarch.rpm
RUN rpm -Uvh erlang-solutions-1.0-1.noarch.rpm
RUN yum update -y
RUN yum install -y erlang

WORKDIR /opt/elixir

RUN git clone https://github.com/elixir-lang/elixir.git /opt/elixir

RUN make clean test

ENV PATH=/opt/elixir/bin:${PATH}

RUN mix do local.hex --force,local.rebar --force
RUN mix archive.install hex phx_new 1.5.4 --force

WORKDIR /opt/app

COPY mix.exs mix.lock ./
COPY config config
COPY priv priv
COPY lib lib

RUN mix deps.get

ENV SECRET_KEY_BASE='secretExampleQrzdplBPdbHHhr2bpELjiGVGVqmjvFl2JEXdkyla8l6+b2CCcvs'
ENV MIX_ENV=prod

RUN mix phx.digest
RUN mix compile
RUN mix release

CMD ["_build/prod/rel/my_app/bin/my_app","start"]

我不确定这是否是令人满意的解决方案,但我愿意接受更优雅的解决方案。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...