【发布时间】:2020-04-18 19:08:30
【问题描述】:
我未能将基本的 Angular 应用程序部署到 Google Cloud Run。该错误表明它在端口 8080 上未正确提供服务,但在我的机器 localhost:8080 上本地运行会显示该应用程序。那么,如果有人有任何想法,我可能需要一些额外的东西来运行云计算?
详情如下:
我创建了一个基本的 Angular 应用程序
ng new test-app
Dockerfile如下
FROM node:latest as node
WORKDIR /app
COPY . .
RUN npm install
RUN npm run build --prod
ENV PORT=8080
FROM nginx:latest
COPY --from=node /app/dist/test-app /usr/share/nginx/html
EXPOSE 8080
CMD ["nginx", "-g", "daemon off;"]
我在本地运行构建的容器,我可以在 localhost:8080 看到它
docker container run -p 8080:80 gcr.io/$GOOGLE_PROJECT/test-app:$IMAGE
然后我部署到 Google Cloud Run 托管。
gcloud run deploy test-app --image gcr.io/$GOOGLE_PROJECT/test-app:$IMAGE --platform managed
但是启动失败,报错
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.
日志中没有其他错误。
谢谢。
我从How to change the port of nginx when using with docker那里得到的有效解决方案
我创建了 nginx.conf 文件,将端口设置为 8080 并将服务器设置为 0.0.0.0
# on alpine, copy to /etc/nginx/nginx.conf
user root;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
sendfile off;
access_log off;
keepalive_timeout 3000;
server {
listen 8080;
root /usr/share/nginx/html;
index index.html;
server_name 0.0.0.0;
client_max_body_size 16m;
}
}
并更新了 Dockerfile 以复制此文件。
FROM node:latest as node
WORKDIR /app
COPY . .
RUN npm install
RUN npm run build --prod
ENV PORT=8080
FROM nginx:alpine
COPY --from=node /app/dist/streamin-app/ /usr/share/nginx/html/
COPY nginx.conf /etc/nginx/
EXPOSE 8080
CMD ["nginx", "-g", "daemon off;"]
【问题讨论】:
-
您可能想研究以下内容...stackoverflow.com/questions/56318026/…...我的理解是您不能在端口 8080 上监听...但是您必须监听端口中的任何内容环境变量...引用的 Q/A 显示了如何在开始使用正确的端口之前修改 nginx。
标签: dockerfile google-cloud-run