Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

300
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda