Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

160
Vistas
Error: connect ECONNREFUSED 127.0.0.1 when connection to anything on localhost

I try to connect from a node.js backend to a different server running on localhost. Every server is running in a docker container. When I execute the http request I receive 'Error: connect ECONNREFUSED 127.0.0.1:80' or 'Error: connect ECONNREFUSED Error: connect ECONNREFUSED 127.0.0.1:4200' when connection to anything on localhost. My code looks the following:

const http = require('http');

const xy = http.get('http://localhost/path', (r) =>{
  console.log(r);
});
xy.on('error', e => {
  console.log(e);
});

const xz = http.get('http://localhost:4200', (r) =>{
  console.log(r);
});
xz.on('error', e => {
  console.log(e);
});

I do not understand, why it does not work. The same request in the browser does work. Connecting to different URLs like google.com does also work. Here is the output of netstat -na:

tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN    
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:5432            0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:4222            0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:4200            0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:9000            0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN  

Does anyone have an idea?

Regards

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

localhost inside a container refers to the container itself, not your laptop/server. So the other service is not running there.

If you want to connect from a container to another container you should use the name of the container instead localhost.

Also, containers need to be inside the same network

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda