启动失败再监听端口
Failed to start and then listen on the port
我有一个 NodeJS 应用程序,我想在 Google 云 运行 上部署。
我已将 Google Cloud Build 配置为在将某些内容推送到主分支上时从 dockerfile 构建容器,并且在构建 Cloud 运行 之后将 运行 新修订。
我的问题是每次我想部署我的应用程序时都会收到以下错误:
Cloud Run error: Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable.
云运行已配置containerPort: 8080
在我的 dockerfile 中,我公开了端口 8080,在 nodejs 中,我使用
设置了简单的 http 服务器
const http = require('http');
const server = http.createServer((req, res) => {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Just for testing purposes\n');
});
const port = parseInt(process.env.PORT, 10) || 8080;
server.listen(port, '0.0.0.0', () => {
console.log('Hello world listening on port', port);
});
我的 Dockerfile
FROM node:12-alpine
# Install app dependencies.
COPY package.json /src/package.json
WORKDIR /src
RUN npm install
# Cloud Run requrement
EXPOSE 8080
COPY index.js /src/index.js
ENTRYPOINT "node index.js"
我错过了什么吗?这是我第一次使用 google 云,所以我确定我需要配置一些我还不知道的东西。
问题出在我的 Dockerfile 中。
我不得不将 ENTRYPOINT "node index.js"
更改为 CMD ["node", "index.js"]
。
但背后的原因我还不知道。
我有一个 NodeJS 应用程序,我想在 Google 云 运行 上部署。 我已将 Google Cloud Build 配置为在将某些内容推送到主分支上时从 dockerfile 构建容器,并且在构建 Cloud 运行 之后将 运行 新修订。
我的问题是每次我想部署我的应用程序时都会收到以下错误:
Cloud Run error: Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable.
云运行已配置containerPort: 8080
在我的 dockerfile 中,我公开了端口 8080,在 nodejs 中,我使用
设置了简单的 http 服务器const http = require('http');
const server = http.createServer((req, res) => {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Just for testing purposes\n');
});
const port = parseInt(process.env.PORT, 10) || 8080;
server.listen(port, '0.0.0.0', () => {
console.log('Hello world listening on port', port);
});
我的 Dockerfile
FROM node:12-alpine
# Install app dependencies.
COPY package.json /src/package.json
WORKDIR /src
RUN npm install
# Cloud Run requrement
EXPOSE 8080
COPY index.js /src/index.js
ENTRYPOINT "node index.js"
我错过了什么吗?这是我第一次使用 google 云,所以我确定我需要配置一些我还不知道的东西。
问题出在我的 Dockerfile 中。
我不得不将 ENTRYPOINT "node index.js"
更改为 CMD ["node", "index.js"]
。
但背后的原因我还不知道。