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

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

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

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 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