无法在GCP云运行上托管Angle 7应用程序

时间:2019-12-06 12:57:47

标签: google-cloud-platform dockerfile angular7 google-cloud-run

我已经构建了一个Angular 7应用程序,当我使用docker从本地计算机运行ng serve命令时,该应用程序可以正常工作。 这是一个简单的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

这是我的docker文件

    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

1 个答案:

答案 0 :(得分:5)

您需要监听PORT env var中定义的端口。因此,在您的Dockerfile中,请执行以下操作:

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