I have a NestJS application that lives in a monorepo. My webpack config has implicit dependencies to generate a package.json, so my dist/apps/server folder contains
- package.json
- package-lock.json
- main.js
- main.js.map
My Dockerfile contains the following:
FROM node:12.22.1-alpine3.10
RUN ls
COPY ../../dist/apps/server .
RUN npm install --production
ENV PORT 3333
EXPOSE 3333
CMD node main.js
I'm able to pull my /dist output into a new directory, npm install, and run the project fine, but for some reason when I run in a docker container, I never get the logs in `app.listen()
await app.listen(port, '0.0.0.0', () => {
Logger.log('Listening at http://localhost:' + port + '/' + globalPrefix);
}).catch(err => console.log(err));
Whenever I hit localhost:3333 I get ERR_EMPTY_RESPONSE
, and after a few minutes my container gives me a fatal out of memory error
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
But on startup, I get all of NestJS logging for the RouteExplorer, RoutesResolver, InstanceLoader, etc... It's only missing the app.listen()
call.
My docker run command is
docker run -p 3333:3333 server
where 'server' is the appropriate tag. Why is my application failing to listen for requests inside a Docker Container but successful when I run locally?