无法在 gcp 云 运行 上托管 angular 7 个应用程序
Unable to host angular 7 application on gcp cloud run
我构建了一个 Angular 7 应用程序,当我使用 docker 从我的本地计算机发出 运行 ng serve
命令时,它可以正常工作。
这是一个简单的 hello world angular 应用程序(没有数据库)。
当我尝试在 GCP Cloud 上托管我的应用程序时 运行。它给我端口错误。
云端错误 运行 :
无法启动并侦听 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
您需要监听 PORT
环境变量中定义的端口。所以在你的 Dockerfile
中做:
CMD ng serve --host 0.0.0.0 --port $PORT
我构建了一个 Angular 7 应用程序,当我使用 docker 从我的本地计算机发出 运行 ng serve
命令时,它可以正常工作。
这是一个简单的 hello world angular 应用程序(没有数据库)。
当我尝试在 GCP Cloud 上托管我的应用程序时 运行。它给我端口错误。
云端错误 运行 :
无法启动并侦听 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
您需要监听 PORT
环境变量中定义的端口。所以在你的 Dockerfile
中做:
CMD ng serve --host 0.0.0.0 --port $PORT