Docker容器无法启动NestJs应用

问题描述 投票:0回答:1

我有NestJs API服务,当使用“ npm run dev”命令运行时,它运行得很好。但是当我进行docker化时,它无法运行该应用程序。我也在容器中尝试了节点版本9,10和12。但是使用run dev命令可以在我的计算机上的节点版本9上顺利运行。我正在使用docker run -it -p 9000:3001 dev-service运行容器。错误如下。

 [email protected] start /app
> node index.js "prod"

TypeError: Cannot read property 'constructor' of undefined
    at Object.<anonymous> (/app/node_modules/cli-highlight/src/theme.ts:4:26)
    at Module._compile (internal/modules/cjs/loader.js:654:30)
    at Module._extensions..js (internal/modules/cjs/loader.js:665:10)
    at Object.require.extensions.(anonymous function) [as .js] (/app/node_modules/ts-node/src/index.ts:406:14)
    at Module.load (internal/modules/cjs/loader.js:566:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
    at Function.Module._load (internal/modules/cjs/loader.js:498:3)
    at Module.require (internal/modules/cjs/loader.js:598:17)
    at require (internal/modules/cjs/helpers.js:11:18)
    at Object.<anonymous> (/app/node_modules/cli-highlight/src/index.ts:3:1)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `node index.js "prod"`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-05-15T03_20_53_617Z-debug.log

Docker文件:

ROM node:9
WORKDIR /app
COPY package.json /app
COPY ormconfig.json /app
RUN npm install
COPY . /app
COPY ormconfig.json /dist/

CMD ["npm", "start", "prod" ]
docker devops nestjs docker-container
1个回答
1
投票

我通过安装粉笔库解决了该问题。发生这种情况的原因是承包商正在寻找粉笔,并且未安装在节点模块中。但这仅在我通过docker运行时才引起。无论如何,在我将依赖关系放入粉笔之后,它就可以工作了。

© www.soinside.com 2019 - 2024. All rights reserved.