Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

298
Views
Connect rails app in Docker container to external Postgresql Database via URL

I have a docker container with web rails app. Also I have external database on my osx machine. If I exec on osx:

psql "postgres://postgres:testing@0.0.0.0:5432/movies_development"

I run okay

If I run it in container I'll receive

psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

Have any ideas how to connect to external database from container? thanks

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

I found a way for connect app in docker container to local database which located on my osx.

0.0.0.0:5432 is an localhost address of container (not a localhost of osx) and we must set new one:

  1. Find osx Ip local address in Preferences > Network Settings (my was 192.168.0.102)
  2. Add this Ip to line listener_address: '192.168.0.102, localhost' of postgresql config file.
  3. Add extra line with Ip 192.168.0.102, host and md5 to pg_hba.conf file
  4. Restart Postgresql

Set connection settings in app via ENV like: postgres://postgres:testing@192.168.0.102:5432/movies_development

about 4 years ago · Santiago Trujillo Report

0

There may be two reasons as per your question :

  • Have you exposed EXPOSE 5432 during your docker image build ? or before starting container with docker run -it -d --name $container_name -p 5432:5432 $image_name ? If NO than you must have to do any of above changes than and than it can connect to externally hosted database.
  • If your are going inside your docker container with docker exec -it $container_name bash and executing command this psql "postgres://postgres:testing@0.0.0.0:5432/movies_development" then there must be psql client installed in your docker container with proper $PATH variable otherwise it will throw error like command not found/no such file or directory.
  • Note: if your application is using some other way to communicate with database than your application will work without psql client program.

Hope this help.Thank you!

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!