Docker 依赖项在编译期间无法查看其配置

Docker 依赖项在编译期间无法查看其配置,docker,elixir,config,elixir-mix,Docker,Elixir,Config,Elixir Mix,我正在尝试将应用程序打包到docker容器中。它依赖于hex包 运行时: 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

我正在尝试将应用程序打包到docker容器中。它依赖于hex包

运行时:

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在编译期间无法读取和初始化其
repo
config:

  • 我觉得我遗漏了一些简单的东西,但我不知道它是什么

    重现该问题的简单回购协议如下所示


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

    这里的问题是Dockerfile,在尝试运行
    mix deps.compile
    时,
    config/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
    ...
    

    你的项目编译得很好。@JustinWood你试过编译docker容器吗?谢谢你,Navin!这是我的一个愚蠢错误。我认为在
    mix deps.compile
    之前添加
    ADD config/config.exs./config/
    就足够了,这样你就不必在每次项目源文件更改时重新编译所有依赖项