Cloud Run 错误:容器无法启动 [英] Cloud Run error: Container failed to start

查看:17
本文介绍了Cloud Run 错误:容器无法启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我未能将基本的 Angular 应用程序部署到 Google Cloud Run.该错误表明它在端口 8080 上未正确提供服务,但在我的机器 localhost:8080 上本地运行会显示该应用程序.那么,如果有人有任何想法,我可能需要一些额外的东西来运行云计算?

I am failing to get a basic Angular app deploying to Google Cloud Run. The error would suggest it is not being served correctly at port 8080, but running locally on my machine localhost:8080 displays the app. So possibly I need something extra for cloud run, if anybody has some idea?

详情如下:

我创建了一个基本的 Angular 应用程序

I create a basic angular app

ng new test-app

Dockerfile如下

The Dockerfile is as follows

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 看到它

Locally I run the built container and I can see it at localhost:8080

docker container run -p 8080:80 gcr.io/$GOOGLE_PROJECT/test-app:$IMAGE

截图

然后我部署到 Google Cloud Run 托管.

I then deploy to Google Cloud Run managed.

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.

日志中没有其他错误.

谢谢.

我从 使用docker时如何更改nginx的端口

我创建了 nginx.conf 文件,将端口设置为 8080 &服务器到 0.0.0.0

I created the nginx.conf file, setting the port to 8080 & server to 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 以复制此文件.

And updated the Dockerfile to copy over this file.

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;"]

推荐答案

我认为与容器监听所有网络接口有关.

I think is related to container listening on all network interfaces.

根据官方文档:

Cloud Run 服务无法启动的一个常见原因是容器内的服务器进程被配置为监听本地主机(127.0.0.1)地址.这是指环回网络接口,不能从容器外部访问,并且因此无法执行 Cloud Run 运行状况检查,导致服务部署失败.

A common reason for Cloud Run services failing to start is that the server process inside the container is configured to listen on the localhost (127.0.0.1) address. This refers to the loopback network interface, which is not accessible from outside the container and therefore Cloud Run health check cannot be performed, causing the service deployment failure.

要解决这个问题,请将您的应用程序配置为启动 HTTP 服务器以监听所有网络接口,通常表示为 0.0.0.0.

To solve this, configure your application to start the HTTP server to listen on all network interfaces, commonly denoted as 0.0.0.0.

这篇关于Cloud Run 错误:容器无法启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆