Cloud Run error: Container failed to start
Cloud Run error: Container failed to start
我无法获得部署到 Google 云 运行 的基本 Angular 应用程序。该错误表明它没有在端口 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
screenshot
然后我部署到 Google 云 运行 托管。
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.
日志中没有其他错误。
谢谢。
我从
中获取的有效解决方案
我创建了 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;"]
我认为与监听所有网络接口的容器有关。
根据官方文档:
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.
To solve this, configure your application to start the HTTP server to
listen on all network interfaces, commonly denoted as 0.0.0.0.
“docker容器运行-p8080:80gcr.io/$GOOGLE_PROJECT/test-app:$IMAGE”
显示您已将本地计算机的端口 8080 映射到镜像的端口 80,这表明您的镜像正在侦听端口 80。
您可以 1) 更改图像或 2) 使用自定义端口部署到云 运行:
gcloud alpha 运行 部署...-端口 80
- 顺便说一句,我根本没有弄乱 nginx
- 我的 docker 文件中只有 EXPOSE 4200
- 我在此处的容器设置中添加了容器端口 4200:
然后它给了我一个 URL 置顶:
这给了我一个无效的主机 header 错误,我通过重新部署我的容器修复了这个错误:
CMD ng serve --host 0.0.0.0 --disable-host-check
查看对此的讨论 here。
我无法获得部署到 Google 云 运行 的基本 Angular 应用程序。该错误表明它没有在端口 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
screenshot
然后我部署到 Google 云 运行 托管。
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.
日志中没有其他错误。
谢谢。
我从
我创建了 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;"]
我认为与监听所有网络接口的容器有关。
根据官方文档:
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.
To solve this, configure your application to start the HTTP server to listen on all network interfaces, commonly denoted as 0.0.0.0.
“docker容器运行-p8080:80gcr.io/$GOOGLE_PROJECT/test-app:$IMAGE”
显示您已将本地计算机的端口 8080 映射到镜像的端口 80,这表明您的镜像正在侦听端口 80。
您可以 1) 更改图像或 2) 使用自定义端口部署到云 运行:
gcloud alpha 运行 部署...-端口 80
- 顺便说一句,我根本没有弄乱 nginx
- 我的 docker 文件中只有 EXPOSE 4200
- 我在此处的容器设置中添加了容器端口 4200:
然后它给了我一个 URL 置顶:
这给了我一个无效的主机 header 错误,我通过重新部署我的容器修复了这个错误:
CMD ng serve --host 0.0.0.0 --disable-host-check
查看对此的讨论 here。