google-cloud-platform - 无法在 gcp 云运行上托管 Angular 7 应用程序
问题描述
ng serve
我已经构建了一个 Angular 7 应用程序,当我使用 docker 从本地机器运行命令时该应用程序可以正常工作。这是一个简单的 hello world Angular 应用程序(没有数据库)。
当我尝试在 GCP Cloud Run 上托管我的应用程序时。它给了我端口错误。
云运行错误:
无法启动并侦听 PORT 环境变量定义的端口。
ERROR: (gcloud.beta.run.deploy) Cloud Run error: Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable. Logs for this revision might contain more information.
Deployment failed
Creating Revision......failed
Setting IAM Policy...............done
Deploying...
Deploying container to Cloud Run service [test-case-builder] in project [test-case-builder] region [us-central1]
Already have image (with digest): gcr.io/cloud-builders/gcloud
这是我的码头文件
FROM node:latest as node
# set working directory
WORKDIR /app
COPY . .
RUN npm install
RUN npm run build --prod
FROM nginx:alpine
COPY --from=node /app/dist/test-case-builder usr/share/nginx/html
CMD ng serve --host 0.0.0.0
解决方案
您需要侦听PORT
env var 中定义的端口。所以在你Dockerfile
做:
CMD ng serve --host 0.0.0.0 --port $PORT
推荐阅读
- python - 如何上传文件夹“图像”中的图像而不是烧瓶中的当前目录
- solr - 使用 apache solr 进行索引
- kubernetes - eksctl 卡在等待节点加入集群
- html - 如何在另一个悬停子元素的一个元素的 ::after 上设置样式
- javascript - 返回某个键:对象的值
- c# - 将 Autofac 容器更改为 SimpleContainer (Caliburn.Micro)
- pandas - 如何在熊猫中使用带有条件的聚合?
- db2 - 使用 CLI 和 SSL 连接到 IBM DB2
- powershell - Powershell move-item 不会从源中删除一些 3D png 文件
- azure - 错误:无法访问密钥保管库引用元数据