按照本指南Distillery
发布一个 elixir/phoenix 项目:
在设定的config/prod.exs
步骤,作者写道:
config :myapp, Myapp.Repo,
adapter: Ecto.Adapters.Postgres,
hostname: "${DB_HOSTNAME}",
username: "${DB_USERNAME}",
password: "${DB_PASSWORD}",
database: "${DB_NAME}",
配置数据库。这里使用${DB_HOSTNAME}
type 来获取环境变量,但不是System.get_env("DB_HOSTNAME")
.
但是,当我在MIX_ENV=prod mix release --env=prod
本地运行和设置环境变量时:
REPLACE_OS_VARS=true PORT=4000 HOST=0.0.0.0 SECRET_KEY_BASE=highlysecretkey DB_USERNAME=postgres DB_PASSWORD=postgres DB_NAME=myapp_dev DB_HOSTNAME=localhost ./_build/prod/rel/myapp/bin/myapp foreground
它循环:
12:05:13.671 [error] Postgrex.Protocol (#PID<0.1348.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (${DB_HOSTNAME}:5432): non-existing domain - :nxdomain
12:05:13.671 [error] Postgrex.Protocol (#PID<0.1347.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (${DB_HOSTNAME}:5432): non-existing domain - :nxdomain
12:05:13.672 [error] Postgrex.Protocol (#PID<0.1344.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (${DB_HOSTNAME}:5432): non-existing domain - :nxdomain
12:05:13.672 [error] Postgrex.Protocol (#PID<0.1346.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (${DB_HOSTNAME}:5432): non-existing domain - :nxdomain
...
长生不老药/凤凰似乎${DB_HOSTNAME}
不知道。
我现在正在使用 Elixir 1.5.2 和 Phoenix 1.3。版本问题?