mbski
Hello,
I am coming back to Elixir world after one year and I wanted to learn also new stuff so I decided to use Docker to my development.
I pulled pgadmin4 and postgresql, set it up according to documentation/articles. It looks like it works fine. I can log in into pgadmin4 through docker, I can open server with credentials given for postgresql container.
Elixir works fine if I want to play with localhost - I have also desktop version of PGAdmin4 and if I use credentials and localhost I can easily create ecto database.
Problem starts when I want to use locally developed Elixir/Phoenix app with PostgreSQL which is in container. I couldn’t find anything that could have helped me resolved this.
Container name: postgres_db,
Username: postgres,
Password: admin123,
Image: postgres
dev.exs
config :weather, Weather.Repo,
username: "postgres",
password: "postgres",
hostname: "postgres_db",
port: 5432,
database: "weather_dev",
stacktrace: true,
show_sensitive_data_on_connection_error: true,
pool_size: 10
Rest left unchanged from initially created files.
PS F:\weather> mix ecto.create
Compiling 28 files (.ex)
Generated weather app08:05:39.563 [error] Postgrex.Protocol (pid<0.416.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (postgres_db:5432): non-existing domain - :nxdomain
** (Mix) The database for Weather.Repo couldn’t be created: connection not available and request was dropped from queue after 2000ms. This means requests are coming in and your connection pool cannot serve them fast enough. You can address this by:
- Ensuring your database is available and that you can connect to it
- Tracking down slow queries and making sure they are running fast enough
- Increasing the pool_size (although this increases resource consumption)
- Allowing requests to wait longer by increasing :queue_target and :queue_interval
See DBConnection.start_link/2 for more information
Thats what i got when i try to create database.
I also tried to use IP address that I put while creating server in postgres, but it still times out.
My another try was also using docker-compose.yml
version: '3.8'
services:
postgres_db:
image: postgres
volumes:
- /var/lib/postgresql/data
container_name: weather
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: weather_dev
ports:
- 5432:5432
Accordingly I updated dev.exs to fit those variables and stopped container created meanually (to omit port conflicts). Effect remains the same. Its not possible to connect Elixir with dockerized Postgres and I cant create database for my app.
Thanks for any help ![]()
Trending in Questions
Other Trending Topics
Latest Phoenix Threads
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
- #ai
- #iex
- #graphql
- #elixirconf-us
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
gmile
In short, in
config/dev.exschangepostgres_dbhostname tolocalhostand try again - it should work:mbski
Actually it works for local instance of postgres but not for postgres container in docker.
I set password provided during setting up contaner, as a host (according to docs) i set up container name.
I get errors about non-existing domain.
With local Postgres everything works
With Postgres in docker I cant create database using mix ecto.create.
D4no0
Is your elixir container part of that docker-compose too? If yes your configuration should work, otherwise you need to specify a custom network, as only containers from the same docker-compose are part of the same network automatically.
mbski
Actually I didnt put Elixir into container as I didn’t do anything in app. Just started and wanted to connect everything together and even meant to work with app development in container.
I meant to work directly from Windows with developing app but having it connected to containerized database. As it’s first time using docker and learning it I dont get whole concepts yet and how it should be resolved.
D4no0
If your elixir application is not in container, then the only way is to expose the port and connect on localhost, just as it was mentioned previously by others.
mbski
I read a little about that but it still doesn’t work.
To create container and expose port I used command:
Using those credentials and IPHost provided while inspecting container I could go into server in pgadmin4. Basically it works.
Now the part that doesn’t work with Elixir
dev.exs
As you can see. Credentials are the same. Hostname is container name in this case:
Obviously i got:
I changed hostname to localhost:
Error is different - result the same. No connection.
It looks like it tries to go into my local instance of postgres but there are invalid credentials for that.
I dont know how it’s supposed to be working with localhost if its signed to local machine and not docker even if i exposed port and it should be working.
I am out of ideas for a now.
Tyson
Most common cause of mismatched credentials when trying to connect to PG in container is that you still have PG running on the host system and are actually connecting to that. Either shut down PG on the host and restart the container, or bind the container port to something other than
5432(and then configure Ecto to use the new port).mbski
And that post with addition of advices above are solutions. I had of course closed Postgres but in the background there were left some tasks. I had to kill them and then Elixir created db and schemas. Perfect.
Other port didnt work by the way, but probably because I hadn’t it opened.
Big thanks for fast reply for silly questions
Natanaelfelixx
Don’t know if you’ve fixed the problem, but in my case, i have the same problem using a postgres container with ruby, and i ran a container with this command:
just added
--network localhostand used localhost on your config file and it should workadamu
For local development I like to use this compose file as a template, which works well with an out of the box phoenix project.