我有一个非常简单的Elixir应用程序
defmodule Example do
require Logger
def greet(word) do
Logger.info "Hello #{word}"
end
end
Example.greet("hheheh")
在mix run
我的Dockerfile看起来像这样
FROM elixir
COPY . /app/
WORKDIR /app
RUN chmod a+rwx -R /app
RUN mix deps get
CMD ["mix", "run"]
但是当我启动容器时,我收到以下错误:
Compiling 1 file (.ex)
warning: redefining module Example (current version loaded from _build/dev/lib/example/ebin/Elixir.Example.beam)
lib/example.ex:1
02:13:22.656 [info] Hello hheheh
** (EXIT from #PID<0.73.0>) an exception was raised:
** (File.Error) could not write to file "/app/_build/dev/lib/example/ebin/Elixir.Example.beam": read-only file system
(elixir) lib/file.ex:719: File.write!/3
(mix) lib/mix/compilers/elixir.ex:388: anonymous fn/4 in Mix.Compilers.Elixir.write_manifest/5
(elixir) lib/enum.ex:1755: Enum."-reduce/3-lists^foldl/2-0-"/3
(mix) lib/mix/compilers/elixir.ex:384: Mix.Compilers.Elixir.write_manifest/5
(mix) lib/mix/compilers/elixir.ex:163: anonymous fn/4 in Mix.Compilers.Elixir.compile_manifest/7
(elixir) lib/agent/server.ex:31: Agent.Server.handle_cast/2
(stdlib) gen_server.erl:601: :gen_server.try_dispatch/4
(stdlib) gen_server.erl:667: :gen_server.handle_msg/5
02:13:22.704 [error] GenServer #PID<0.89.0> terminating
** (File.Error) could not write to file "/app/_build/dev/lib/example/ebin/Elixir.Example.beam": read-only file system
(elixir) lib/file.ex:719: File.write!/3
(mix) lib/mix/compilers/elixir.ex:388: anonymous fn/4 in Mix.Compilers.Elixir.write_manifest/5
(elixir) lib/enum.ex:1755: Enum."-reduce/3-lists^foldl/2-0-"/3
(mix) lib/mix/compilers/elixir.ex:384: Mix.Compilers.Elixir.write_manifest/5
(mix) lib/mix/compilers/elixir.ex:163: anonymous fn/4 in Mix.Compilers.Elixir.compile_manifest/7
(elixir) lib/agent/server.ex:31: Agent.Server.handle_cast/2
(stdlib) gen_server.erl:601: :gen_server.try_dispatch/4
(stdlib) gen_server.erl:667: :gen_server.handle_msg/5
Last message: {:"$gen_cast", {:cast, #Function<8.32884957/1 in Mix.Compilers.Elixir.compile_manifest/7>}}
State: {[{:module, Example, :module, "lib/example.ex", nil, <<70, 79, 82, 49, 0, 0, 6, 200, 66, 69, 65, 77, 69, 120, 68, 99, 0, 0, 0, 149, 131, 104, 2, 100, 0, 14, 101, 108, 105, 120, 105, 114, 95, 100, 111, 99, 115, 95, 118, 49, 108, 0, 0, 0, ...>>}], [{:source, "lib/example.ex", [Logger, Kernel], [:erlang, String.Chars], [{Example, %{{:greet, 1} => '\b'}}, {Kernel, %{{:def, 2} => [3], {:defmodule, 2} => [1], {:to_string, 1} => [4]}}, {Logger, %{{:info, 1} => [4]}}], [{Logger, %{{:bare_log, 3} => [4]}}, {String.Chars, %{{:to_string, 1} => [4]}}, {:erlang, %{{:++, 2} => [4]}}], []}]}
所以,该程序运行,但我不确定我是否真的理解了其余的错误。
答案 0 :(得分:0)
存在某种文件模式时间和权限问题:
编译1个文件(.ex)警告:重新定义模块示例(当前 从_build / dev / lib / example / ebin / Elixir.Example.beam加载的版本。
LIB / example.ex:1
这意味着mix run
在加载代码后尝试重新编译代码。
我的猜测是您的docker镜像是使用MIX_ENV值构建的,该值与mix run
的默认值不同。 MIX_ENV,prod,test,dev ...和不同的混合命令有3个不同的值
使用不同的值来查找预先构建的BEAM文件。
我会尝试将mix run命令更改为:
env MIX_ENV=prod mix run
答案 1 :(得分:0)
问题可能出在你的Dockerfile中:
RUN mix deps get
这应该是:
RUN mix deps.get
(注意期间)
没有它然后&#34;混合运行&#34;将尝试重建您的依赖项。在您的容器中,您运行的是只读文件系统,因此您无法构建新内容。