0

I have a node app using express, and am trying to deploy using heroku.

import http from 'http';
import express from 'express';
import pagesRouter from './routes/pages';
import nconf from 'nconf';

const app = express();

app.use(pagesRouter);

const port = process.env.PORT || nconf.get('port');

server = http.createServer(app);
server.listen(port);

And this works fine locally to create the server, and serve all the routes I've created.

I've then tried to dockerize this to deploy to heroku by creating a dockerfile, and heroku.yml for this:

FROM node:18.12.1
WORKDIR ./
COPY . .
ENV NODE_ENV production
RUN npm ci
RUN npm run build
RUN npm prune --production
EXPOSE 6001
CMD ["npm", "run", "start"]
build:
  docker:
    web: Dockerfile

Looking in the logs of heroku, I can see this is running and starting correctly, however when I try to click on 'open app' to view the app running at https://www.damp-garden-69923.herokuapp.com/ I get the following error:

This site can’t be reached

www.damp-garden-69923.herokuapp.com’s server IP address could not be found.

ERR_NAME_NOT_RESOLVED

I'm not sure if I'm missing something, but would appreciate any help

Note: I am using the GUI rather than heroku CLI

1 Answers1

0

according to this answer in here you shouldn't use expose you should use the ports in you docker compose file.

  • It's a heroku.yml file rather than a docker compose, and the EXPOSE is apparently just ignored when using heroku, as heroku passes it's own port as an environmental variable – Philip Saville Jul 22 '23 at 16:45