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

791
Visualizações
Why can't I connect my application (docker) to the database?

I've the following problem: I created a simple NodeJS app, where there is a listening server on port number 3000. I definded some simple operations, like post, put and read. Anyway, this operation are performed into a database executed as Docker Container, on port number 5432 (postgres). In local, the application works perfectly. Instead, if I try to Dockerize my app and execute it:

FROM node:16
WORKDIR /app
COPY package*.json /app
RUN npm install
COPY . /app
CMD ["npm", "start"]

I receive the following error:

      original: Error: connect ECONNREFUSED 127.0.0.1:5432
          at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1157:16) {
        errno: -111,
        code: 'ECONNREFUSED',
        syscall: 'connect',
        address: '127.0.0.1',
        port: 5432
      }

}

As if it was not possible to connect to the postgres db. Why this happens? In local I perfectly can connect to postgres, but if I execute my app as a Docker Container, I can't connect to postgres. Thank you everybody!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

A container has its own localhost so connecting to localhost would try to connect to a database running within the container and as you don't have a database server running within the container on localhost you can't connect to it.

You can connect to the database running on the host using host.docker.internal (for Mac/ Windows) as a hostname to refer to the host or start the container in the host network (only possible on Linux) and then it should work.

Have a look at this answer which goes into more details.

about 4 years ago · Juan Pablo Isaza 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