heroku - 在容器中部署时 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 构建,并且部署成功!那么,我做错了什么?
解决方案
推荐阅读
- ruby - Why does Ruby YAML sometimes add '2' after pipe char (|)?
- c# - 将 typeof(x) 类型传递给泛型方法
- azure - 在 Flutter 中从 Azure Cosmos DB 获取数据?
- css - 如何创建背景图像的静态网格
- python-3.x - 我在 python3 中使用 seaborn 可视化数据集,但它给了我一个错误。/ 不支持的操作数类型:“str”和“int”
- java - 尝试在 azure 中创建新存储桶时出现 java.net.UnknownHostException
- featuretools - 功能工具时间序列数据按月年分组
- maven - 我可以从 nexus 部署到 ARM 吗?
- reactjs - 从反应组件内部的 iframe 访问 html 元素
- auth0 - Style Auth0 的小屏幕通用登录标题?