我正在将一个 Elixir/Phoenix 应用程序从 1.7.4 升级到 1.11.4,并将其 docker 化。我已经设法更新依赖项并使用
iex -S mix phx.server
运行它。此外,我能够在本地生成一个版本并成功运行它,如下所示:
MIX_ENV=prod mix release jujuba
Compiling 2 files (.ex)
Compiling crate file_worker in release mode (native/file_worker)
Finished release [optimized] target(s) in 0.85s
* assembling jujuba-24.61.1 on MIX_ENV=prod
* using config/runtime.exs to configure the release at runtime
Release created at _build/prod/rel/jujuba!
# To start your system
_build/prod/rel/jujuba/bin/jujuba start
Once the release is running:
# To connect to it remotely
_build/prod/rel/jujuba/bin/jujuba remote
# To stop it gracefully (you may also send SIGINT/SIGTERM)
_build/prod/rel/jujuba/bin/jujuba stop
To list all commands:
_build/prod/rel/jujuba/bin/jujuba
当我用
_build/prod/rel/jujuba/bin/jujuba start
运行它时,它会正常启动。但是,当我构建它的图像并尝试运行它时失败了。
我正在使用这些命令构建和运行 docker:
docker build --progress=plain . -t jujuba:24.61.1
docker run -p 4000:4000 jujuba:24.61.1
它给出了这个错误:
docker run -p 4000:4000 jujuba:24.61.1
warning: :simple_one_for_one strategy is deprecated, please use DynamicSupervisor instead
(elixir 1.11.4) lib/supervisor.ex:604: Supervisor.init/2
(stdlib 3.17.2.2) supervisor.erl:330: :supervisor.init/1
(stdlib 3.17.2.2) gen_server.erl:423: :gen_server.init_it/2
(stdlib 3.17.2.2) gen_server.erl:390: :gen_server.init_it/6
(stdlib 3.17.2.2) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
{"Kernel pid terminated",application_controller,"{application_start_failure,jujuba,{bad_return,{{'Elixir.jujuba.Application',start,[normal,[]]},{'EXIT',{undef,[{'Elixir.jujuba.Application',start,[normal,[]],[]},{application_master,start_it_old,4,[{file,\"application_master.erl\"},{line,293}]}]}}}}}"}
Kernel pid terminated (application_controller) ({application_start_failure,jujuba,{bad_return,{{'Elixir.jujuba.Application',start,[normal,[]]},{'EXIT',{undef,[{'Elixir.jujuba.Application',start,[normal,[]],[]},{application_master,start_it_old,4,[{file,"application_master.erl"},{line,293}]}]}}}}})
我的 Dockerfile 看起来像这样
FROM hexpm/elixir:1.11.4-erlang-24.3.4.8-alpine-3.17.0 as build
RUN apk add --update git build-base
RUN apk add curl
RUN mkdir jujuba
WORKDIR jujuba
ENV MIX_ENV prod
RUN curl https://sh.rustup.rs -sSf | sh -s -- --quiet -y
RUN source "$HOME/.cargo/env"
RUN mix do local.hex --force, local.rebar --force
RUN mkdir ./apps
RUN mkdir ./apps/jujuba
COPY mix.* ./
COPY ./mix.* ./apps/jujuba/
COPY ./mix.* ./apps/jujuba/
RUN mix deps.get --only $MIX_ENV
RUN mix deps.compile
COPY config ./config
RUN mix phx.digest
COPY rel ./rel
RUN PORT=4000 MIX_ENV=prod mix release jujuba
FROM alpine:3.17 AS app
# install runtime dependencies
RUN apk add --update openssl postgresql-client
# copy release to app container
COPY --from=build ./jujuba/_build/prod/rel/jujuba/ .
CMD ["sh", "/bin/jujuba", "start"]
你对我做错了什么有什么暗示吗?
这是我的主管的样子:
defmodule Jujuba.Application do
use Application
require Logger
def start(_type, _args) do
# Define workers and child supervisors to be supervised
children = [
# Telemetry
JujubaWeb.Telemetry,
# Start the endpoint when the application starts
JujubaWeb.Endpoint,
# Start the Ecto repository
Jujuba.Repo.Master,
# Start the flow builder supervisor
{FlowBuilder.Supervisor, []},
# Start AMQP Client
{AMQPClient.Supervisor, []},
# Start the generic contact import flow builder supervisor
ContactImportFlowBuilder.Supervisor,
# Start your own worker by calling: Jujuba.Worker.start_link(arg1, arg2, arg3)
# Connection to Redis
{Redix,
name: :redix,
host: Application.get_env(:redix, :host),
port: Application.get_env(:redix, :port),
password: Application.get_env(:redix, :password)},
{Phoenix.PubSub, name: JujubaWeb.PubSub, adapter: Phoenix.PubSub.PG2}
]
JujubaWeb.PlugPipelineInstrumenter.setup()
JujubaWeb.MetricsExporter.setup()
Jujuba.RepoInstrumenter.setup()
JujubaWeb.PhoenixInstrumenter.setup()
opts = [strategy: :one_for_one, name: Jujuba.Supervisor]
Supervisor.start_link(children, opts)
end
end