首页 > 解决方案 > 在容器中部署时 Heroku 进程以状态 1 退出

问题描述

我正在尝试将 docker 容器部署到 Heroku 并收到此错误。

2021-11-01T14:55:38.123348+00:00 heroku[web.1]: State changed from crashed to starting
2021-11-01T14:55:44.185616+00:00 heroku[web.1]: Starting process with command `node dist/main`
2021-11-01T14:56:12.482091+00:00 heroku[web.1]: Process exited with status 1
2021-11-01T14:56:12.644858+00:00 heroku[web.1]: State changed from starting to crashed

我尝试修复 1 和 2 在这里评论,但它仍然不起作用: https ://help.heroku.com/P1AVPANS/why-is-my-node-js-app-crashing-with-an-r10-error

我的应用程序是在 Docker 容器中运行的 NestJS 中构建的,在本地它工作正常,问题是当我部署到 Heroku 时。这是我的 Dockerfile:

FROM node:12.13-alpine As development

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install glob rimraf ansi-styles && npm install --only=development

COPY . .

RUN npm run build

FROM node:12.13-alpine as production

ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm ci --only=production

RUN apk add --no-cache bash

COPY . .

COPY --from=development /usr/src/app/dist ./dist

CMD ["node", "dist/main"]

和我的 main.ts 来自应用程序:

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { WinstonModule } from 'nest-winston';
import { AllExceptionFilter } from './filters/all-exception.filter';
import { ConfigService } from '@nestjs/config';
import { ValidationPipe } from '@nestjs/common';
import * as helmet from 'helmet';
import { format, transports } from 'winston';

const { combine, timestamp, prettyPrint } = format;

async function bootstrap() {
  const app = await NestFactory.create(AppModule,{
    logger: WinstonModule.createLogger({
      exitOnError: false,
      format: combine(
        timestamp(),
        prettyPrint()
      ),
      transports: [
        new transports.File({
        filename: 'logs/portalInfo.log',
        level: "http",
        maxsize:10000000,
        maxFiles: 10
       }),
        new transports.File({ 
        filename: 'logs/portalError.log',
        level: "error",
        maxsize:10000000,
        maxFiles: 10 }),
      ],
       exceptionHandlers: [new transports.File({
        filename: 'logs/portalExceptions.log',
        maxsize:10000000,
        maxFiles: 10 })]
    })
    }
  );

  const configService = app.get(ConfigService);
  app.use(helmet());
  app.enableCors();
  app.useGlobalFilters(new AllExceptionFilter());
  app.useGlobalPipes(new ValidationPipe());
  
  await app.listen(process.env.PORT || 3000, '0.0.0.0');
}
bootstrap();

我尝试的另一件事是制作一个新的 Nestjs proyect(使用 nestjs cli 搭建)并使用上面的 Dockerfile 构建,并且部署成功!那么,我做错了什么?

标签: herokudockerfilenestjs

解决方案


推荐阅读