Home > Enterprise >  Building Docker Images with heroku.yml (failed to bind to port)
Building Docker Images with heroku.yml (failed to bind to port)

Time:07-23

my Dockerfile is

FROM node:16
WORKDIR /app
COPY package*.json ./

RUN npm install
copy . /app

# Expose 9000
CMD ["npm","start"]

heroku.yml

build:
  docker:
    web:
       Dockerfile

index.js contains (using express)

const PORT = process.env.PORT || 3002;
const HOST = "localhost";
app.listen(PORT,HOST, () => console.log(`listening on port ${PORT}`));

After git push heroku master the web process failing to bind after 1 minute of starting. How can i resolve this ?

listening on port 25941
Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
Stopping process with SIGKILL
Process exited with status 137
State changed from starting to crashed

CodePudding user response:

After doing some reading on Heroku, it seems it specifies a random port. It also says here that Dockerfile EXPOSE is not respected.

I'd guess the problem is with HOST:

const HOST = "localhost";
app.listen(PORT,HOST, () => console.log(`listening on port ${PORT}`));

The HOST parameter can be omitted and just the callback can be passed instead:

app.listen(PORT, () => console.log(`listening on port ${PORT}`));
  • Related