编译期间依赖项无法看到它的configuration

我正在尝试在Docker容器中打包应用程序。 它依赖于可authablehex包。

运行时:

 docker build --tag "testing:0.1" --file Dockerfile . 

…我收到以下编译错误:

 == Compilation error on file lib/authable/repo.ex == ** (ArgumentError) missing :adapter configuration in config :authable, Authable.Repo lib/ecto/repo/supervisor.ex:50: Ecto.Repo.Supervisor.compile_config/2 lib/authable/repo.ex:6: (module) (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6 could not compile dependency :authable, "mix compile" failed. You can recompile this dependency with "mix deps.compile authable", update it with "mix deps.update authable" or clean it with "mix deps.clean authable" 

该错误表示在编译期间Authable无法读取和初始化其repoconfiguration:

  1. 可授权/ repo.ex
  2. config.exs

我觉得有一些简单的东西我错过了,但我不知道它是什么。

重现这个问题的一个简单的回购是在这里 – https://github.com/gmile/test_authable_docker 。

更新 。 明确表示只有在docker编译时才会发生错误(例如在主机macOS上编译时一切正常)。

这里的问题是你的Dockerfile,在运行mix deps.compileconfig/config.exs还不可用。

原始的Dockerfile内容:

 # Install and compile project dependencies COPY mix.* ./ RUN mix deps.get RUN mix deps.compile RUN mix ecto.create RUN mix ecto.migrate -r Authable.Repo # Add project sources COPY . . 

mix compile之前将其更改为复制源可解决此问题:

 .... RUN mix deps.get # Add project sources COPY . . RUN mix deps.compile ...