I’m attempting to setup a rootless docker-compose deployment of an Phoenix app using Podman 4. Unfortunately, when starting the Phoenix App, Ecto throws an error, unable to resolve the database’s domain name (db
in the example below)
[error] Postgrex.Protocol (#PID<0.1965.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (db:5432): non-existing domain - :nxdomain
While troubleshooting I’ve overwritten the phoenix app’s container start command with the following:
command: [“eval”, “IO.inspect :gen_tcp.connect(‘db’, 5432, [packet: :raw, mode: :binary, active: false], 3000)”]
Which yields {:ok, #Port<0.6>}
, Indicating to me this is some sort of issue with how Postgrex is utilizing gen_tcp.
I also tried using inet_res directly:
command: [“eval”, “IO.inspect :inet_res.resolve(‘db’, :in, :a)”]
Which seems to successfully resolve the IP:
{:ok,
{:dns_rec, {:dns_header, 1, true, :query, false, false, true, false, false, 0},
[{:dns_query, 'db', :a, :in, false}],
[{:dns_rr, 'db', :a, :in, 0, 86400, {10, 89, 0, 35}, :undefined, [], false}],
[], []}}
When I try to use other valid domains besides db
and its alias’s, including localhost, I get connection errors. That makes sense because there is no Postgres instance listening there, but it seems to pass the name resolution step just fine.
The final piece that I’ve noticed on my local machine is that :inet_res.resolve
does not resolve domains specified in the host file (/etc/hosts), but gen_tcp.connect
seems to. Though the hosts file is not how domain names are set with docker-compose / podman.
Here’s my Repo config (the commented out parts have been tried but haven’t changed the error)
config :phoenix_app, PhoenixApp.Repo,
# ssl: true,
# socket_options: [:inet6],
url: "ecto://user:pass@db/phoenix_app",
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10")
Have I simply misconfigured something? Is this a bug in Postgrex? What suggestions do you have for debugging this error?