micah
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?
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #ai
- #genstage
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex











First 10 of 11 Posts
joey_the_snake
Is it possible your Postgres container is not started when your app tries to connect?
micah
@joey_the_snake I also had this concern when I started debugging this issue and setup a healthcheck for the postgres database and a dependency on that healthcheck to pass before starting the app. From the console logs I can see that this seems to work: It logs that the database is ready before the application starts.
I believe this also would be seen (at least intermittently) when running the application with the
evalcommands. Theevalcommands show that, given the correct configuration, Erlang is at least capable of resolving the domain.Please let me know if you think of anything else to try!
hst337
Could you please paste a stacktrace of the logged error?
hst337
By the way, since
dockerreleased rootless support, I do not usepodman, because it is still buggy andpodman-composeis still in a buggy alpha statemicah
Here are the relevant logs
@hst337 FWIW I’m using docker-compose with podman, not podman-compose. I’ll look into switching to docker, but if utilities like
pingand modules likegen_tcpcan resolve the domain, wouldn’t that indicate that the issue is some higher-level configuration problem?hst337
Hmm, could you please share relevant parts of your docker-compose file?
micah
Of course. Here is my docker-compose file:
And my Containerfile if that is at all interesting:
I’m really very stumped with this one, so any suggestions are appreciated!
sobojack
@micah Any progress on this one?
D4no0
I can bet the postgres service was not starting from configuration issues or healthcheck, looks suspicious and unnecessary. I have started countless docker-composes like this one and they all worked flawlessly, just omit the heartbeat part.
sobojack
I am getting that same domain error is him. I know my postgres is up and running. Obviously my setup is a bit different but am still getting that same error