公开端口8080和3000以进行云运行部署 [英] Expose Both Ports 8080 and 3000 For Cloud Run Deployment

查看:229
本文介绍了公开端口8080和3000以进行云运行部署的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TL:DR -我正在尝试将我的MERN堆栈应用程序部署到GCP的Cloud Run。

TL:DR - I am trying to deploy my MERN stack application to GCP's Cloud Run. Struggling with what I believe is a port issue.

我的React应用程序位于 client 文件夹内部我的Node.js 应用程序。

My React application is in a client folder inside of my Node.js application.

这是我的一个同时运行前端和后端的 Dockerfile

Here is my one Dockerfile to run both the front-end and back-end:

FROM node:13.12.0-alpine
WORKDIR /app
COPY . ./

# Installing components for be connector
RUN npm install --silent  
WORKDIR /app/client
RUN npm install --silent

WORKDIR /app
RUN chmod +x /app/entrypoint.sh
ENTRYPOINT [ "/app/entrypoint.sh" ]

...这是我的 entrypoint.sh 文件:

... and here is my entrypoint.sh file:

#!/bin/sh
node /app/index.js &
cd /app/client
npm start

docker-compose up 在本地工作,并且 docker run -p 8080:8080 -p 3000:3000< image_id> 运行我构建的映像。端口8080用于Node,端口3000用于React应用。但是,在Cloud Run上,该应用程序无法运行。当我访问部署到Cloud Run的应用程序时,前端最初会加载一秒钟,但随后在尝试向API发出请求时该应用程序崩溃。

docker-compose up works locally, and docker run -p 8080:8080 -p 3000:3000 <image_id> runs the image I built. Port 8080 is for Node and port 3000 for the React app. However, on Cloud Run, the app does not work. When I visit the app deployed to Cloud Run, the frontend initially loads for a split second, but then the app crashes as it attempts to make requests to the API.

< a href = https://i.stack.imgur.com/mweUP.png rel = nofollow noreferrer>
高级设置 中,有一个容器端口,默认为8080。我尝试将其更改为3000,但均无效。我无法输入8080,3000,因为该字段仅对端口使用有效的整数。是否可以像这样同时将React + Node部署到Cloud Run?我如何让Cloud Run在8080和3000上都收听,而不是在2个中只收听一个?

In the Advanced Settings, there is a container port which defaults to 8080. I've tried changing this to 3000, but neither works. I cannot enter 8080,3000, as the field takes valid integers only for the port. Is it possible to deploy React + Node at the same time to Cloud Run like this? How can I have Cloud Run listen on both 8080 and 3000, as opposed to just 1 of the 2?

谢谢!

推荐答案

当前不可能。

相反,您可以在Cloud Run中运行多个进程,而是根据URL使用nginx代理它们之间的请求,类似于在此答案中推荐了什么。

Instead, you can run multiple processes inside Cloud Run, but instead use nginx to proxy requests between them depending on the URL, similar to what's recommended in this answer.

这篇关于公开端口8080和3000以进行云运行部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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