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

5K
Vistas
localhost didn’t send any data. ERR_EMPTY_RESPONSE nodejs

I'm trying to convert this app to docker but I'm getting this error.

Here's my express.js file

const express = require("express");
const app = express();
const portNumber = 3000;
const sourceDir = "dist";
const expressStaticGzip = require("express-static-gzip");
app.use(
  "/",
  expressStaticGzip(sourceDir, {
    enableBrotli: true,
    orderPreference: ["br", "gz"],
    setHeaders: function(res, path) {
      res.setHeader("Cache-Control", "public, max-age=31536000");
    }
  })
);

app.listen(portNumber, () => {
  console.log(`Express web server started: http://localhost:${portNumber}`);
  console.log(`Serving content from /${sourceDir}/`);
});

here's my dockerfile

FROM node:14
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
CMD [ "node", "express.js" ]

Help is appreciated.

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

This is a very common error. When you're broadcasting within a docker container you usually have to listen on host 0.0.0.0 not just localhost. If you listen on localhost docker won't be able to route traffic from outside of the container to the loopback interface within the container.

You can fix this by updating your express code to listen on 0.0.0.0. I believe that's this:

app.listen(portNumber, "0.0.0.0", () => {
  console.log(`Express web server started: http://0.0.0.0:${portNumber}`);
  console.log(`Serving content from /${sourceDir}/`);
});

You'll then need to run the dockerfile with something like:

docker build -t node-app .
docker run -p 3000:3000 node-app
over 4 years ago · Santiago Trujillo Denunciar

0

I was running the angular application using the command ng serve and facing the same problem.

Because the live development server listens to http://localhost:4200 by default.

than I used the command ng serve --host 0.0.0.0 to run the angular project and that solved my problem.

over 4 years ago · Santiago Trujillo 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