首页 > 解决方案 > 无法在 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

标签: google-cloud-platformdockerfileangular7google-cloud-run

解决方案


您需要侦听PORTenv var 中定义的端口。所以在你Dockerfile做:

CMD ng serve --host 0.0.0.0 --port $PORT

推荐阅读